axnsan12 / drf-yasg

Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
https://drf-yasg.readthedocs.io/en/stable/
Other
3.37k stars 434 forks source link

AttributeError at /swagger/ 'NoneType' object has no attribute 'title' #390

Open farshadff opened 5 years ago

farshadff commented 5 years ago

i am using this package with python rest famrwork api and i installed rest framework and its working fine and i installed this packge and added that to installed packages and here is what i changed in my url.py : ` from django.contrib import admin from django.urls import include, path from rest_framework import routers from django.shortcuts import redirect from tutorial.quickstart import views from drf_yasg import openapi from drf_yasg.views import get_schema_view from rest_framework import permissions router = routers.DefaultRouter() router.register(r'users', views.UserViewSet) router.register(r'groups', views.GroupViewSet)

SchemaView = get_schema_view( openapi.Info( title="asdasdsad", default_version='v1', ), public=False, permission_classes=(permissions.AllowAny,) ) swagger_info = openapi.Info( title="Snippets API", default_version='v1', description="""This is a demo project for the drf-yasg Django Rest Framework library.

The swagger-ui view can be found here.
The ReDoc view can be found here.
The swagger YAML document can be found here.

You can log in using the pre-existing admin user with password passwordadmin.""", # noqa terms_of_service="https://www.google.com/policies/terms/", contact=openapi.Contact(email="contact@snippets.local"), license=openapi.License(name="BSD License"), )

SchemaView = get_schema_view( validators=['ssv', 'flex'], public=True, permission_classes=(permissions.AllowAny,), ) and in the end i use paths like below : urlpatterns = [ path('', include(router.urls)),

re_path("^swagger(?P.json|.yaml)$", SchemaView.without_ui(cache_timeout=0), name='schema-json'),

path("swagger/", SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), path("redoc/", SchemaView.with_ui('redoc', cache_timeout=0), name='schema-redoc'), path('admin/', admin.site.urls), ] now when i run python manage.py runserver and when i navigate to localhost:8000/swagger i get this error : AttributeError at /swagger/ 'NoneType' object has no attribute 'title'

Request Method: GET Request URL: http://127.0.0.1:8000/swagger/ Django Version: 2.2.2 Python Executable: /usr/bin/python Python Version: 3.6.8 Python Path: ['/home/farshad/Desktop/django', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/farshad/.local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages'] Server time: Thu, 20 Jun 2019 08:11:35 +0000 Installed Applications: ['rest_framework', 'drf_yasg', 'django.contrib.admin', `

kalikim commented 4 years ago

i am also facing the same problem and since no one has replied to this error let me hope you found the solution ? if so share the solution with me

farshadff commented 4 years ago

@kalikim no i didnt find any solution to this and i think i switched to another package

bolerap commented 4 years ago

Provide info for get_schema_view look like below

schema_view = get_schema_view(
    info=openapi.Info(
        title="Test API",
        default_version="v1",
        description="Test description",
        terms_of_service="https://www.google.com/policies/terms/",
        contact=openapi.Contact(email="contact@example.com"),
        license=openapi.License(name="BSD License"),
    ),
    validators=["ssv", "flex"],
    public=True,
    permission_classes=(permissions.AllowAny,),
)
ronbrian commented 2 years ago

Add the following lines to your settings.py and that error should be gone

 SWAGGER_SETTINGS = {
    'DEFAULT_INFO': 'urls.swagger_info',   #your swagger_info on your urls page
}

REDOC_SETTINGS = {
    'SPEC_URL': ('schema-json', {'format': '.json'}),
}