我试图在我的一个项目中实现 django-rest-swagger ,但是出现以下错误:
Internal Server Error: /api/docs/
Traceback (most recent call last):
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/rest_framework/views.py", line 495, in dispatch
response = self.handle_exception(exc)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/rest_framework/views.py", line 455, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/rest_framework/views.py", line 492, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/rest_framework_swagger/views.py", line 32, in get
schema = generator.get_schema(request=request)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/rest_framework/schemas/generators.py", line 281, in get_schema
links = self.get_links(None if public else request)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/rest_framework/schemas/generators.py", line 319, in get_links
link = view.schema.get_link(path, method, base_url=self.url)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/rest_framework/schemas/inspectors.py", line 217, in get_link
fields += self.get_filter_fields(path, method)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/rest_framework/schemas/inspectors.py", line 412, in get_filter_fields
fields += filter_backend().get_schema_fields(self.view)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django_filters/rest_framework/backends.py", line 131, in get_schema_fields
filterset_class = self.get_filterset_class(view, queryset)
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django_filters/rest_framework/backends.py", line 73, in get_filterset_class
class AutoFilterSet(self.filterset_base):
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django_filters/filterset.py", line 71, in __new__
new_class.base_filters = new_class.get_filters()
File "/Users/hugovillalobos/Documents/Code/TaxistasProject/TaxistasVenv/lib/python3.6/site-packages/django_filters/filterset.py", line 352, in get_filters
"%s" % ', '.join(undefined)
TypeError: 'Meta.fields' contains fields that are not defined on this FilterSet: basrcode
我遵循了文档here,但是它不起作用。
这是我的urls.py
的代码:
from django.contrib import admin
from django.conf.urls.i18n import i18n_patterns
from django.urls import path, include
from rest_framework.authtoken import views
from django.conf.urls.static import static
from django.conf import settings
from rest_framework_swagger.views import get_swagger_view
api_url_patterns = [
path('docs/',get_swagger_view(title="Taxistas API")),
path('users_manager/', include('UsersManagerApp.urls')),
path('general/', include('GeneralApp.urls')),
]
urlpatterns = [
path('api-token-auth/', views.obtain_auth_token),
path('api-auth/', include('rest_framework.urls')),
path('admin/', admin.site.urls),
path('api/', include(api_url_patterns)),
]
我检查了版本支持,但似乎一切正常:django == 2.1.7,djangorestframework == 3.9.2和django-rest-swagger == 2.2.0。