我的django-swagger正在使用我的API。但是,当我尝试将Djoser网址包含在我的urlpatterns中时,我得到以下回溯:
Internal Server Error: /docs/
Traceback (most recent call last):
File "/Users/bo/env/home365/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/Users/bo/env/home365/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/bo/env/home365/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, 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/bo/env/home365/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/bo/env/home365/lib/python3.6/site-packages/django/views/generic/base.py", line 69, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework_swagger/views.py", line 32, in get
schema = generator.get_schema(request=request)
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/schemas/generators.py", line 286, in get_schema
links = self.get_links(None if public else request)
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/schemas/generators.py", line 324, in get_links
link = view.schema.get_link(path, method, base_url=self.url)
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/schemas/inspectors.py", line 195, in get_link
fields += self.get_serializer_fields(path, method)
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/schemas/inspectors.py", line 337, in get_serializer_fields
for field in serializer.fields.values():
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/serializers.py", line 363, in fields
for key, value in self.get_fields().items():
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/serializers.py", line 1026, in get_fields
field_names, declared_fields, extra_kwargs
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/serializers.py", line 1373, in get_uniqueness_extra_kwargs
field_names, declared_fields, extra_kwargs
File "/Users/bo/env/home365/lib/python3.6/site-packages/rest_framework/serializers.py", line 1455, in _get_model_fields
if '.' in source or source == '*':
TypeError: argument of type 'CharField' is not iterable
这是我的urls.py:
from django.contrib import admin
from django.conf import settings
from django.urls import include, path, re_path
from rest_framework.routers import DefaultRouter
from rest_framework_swagger.views import get_swagger_view
from apps.core import api as core_api
schema_view = get_swagger_view(title='365home API')
router = DefaultRouter()
router.register(r'core/fabric', core_api.FabricViewSet,
base_name='FabricViewSet')
urlpatterns = [
path('docs/', schema_view),
path('admin/', admin.site.urls),
path('v1/api/', include(router.urls)),
path('djoser/', include('djoser.urls')),
path('', include('apps.frontend.urls')),
]
如果我包含djoser.urls.jwt或djoser.urls.authotoken - 没有问题。如果我包含djoser.urls.base - 会出现问题。
在这个问题上找不到很多。
我使用的是django 2.0.1,DRF 3.8.2,django-rest-swagger 2.1.2和djoser 1.1.5。
有没有人遇到这个问题?