django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

Open cegprakash opened this issue 6 years ago • 3 comments

Here is my requirements.py

djangorestframework==3.5.4
Django==1.8.1
django-rest-swagger==2.0.7

I created a separate app for swagger using python3 manage.py startapp swagger

urls.py

from django.conf.urls import include, url
from swagger.views import SwaggerSchemaView
urlpatterns = [
    url(r'^docs/', SwaggerSchemaView.as_view(), name='swagger')
]

views.py

from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.schemas import SchemaGenerator
from rest_framework.views import APIView
from rest_framework_swagger import renderers


class SwaggerSchemaView(APIView):
    permission_classes = [AllowAny]
    renderer_classes = [
        renderers.OpenAPIRenderer,
        renderers.SwaggerUIRenderer
    ]

    def get(self, request):
        generator = SchemaGenerator()
        schema = generator.get_schema(request=request)

        return Response(schema)

Global settings.py

INSTALLED_APPS = (
   ..
   .. 
   'swagger',
    'rest_framework_swagger',
)

Global urls.py

urlpatterns = [
    url(r'^docs/', include('swagger.urls')),
]

Traceback (most recent call last): File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/site-packages/django/core/urlresolvers.py", line 394, in urlconf_module return self._urlconf_module AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.5/wsgiref/handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 63, in call return self.application(environ, start_response) File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 170, in call self.load_middleware() File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/site-packages/django/core/handlers/base.py", line 52, in load_middleware mw_instance = mw_class() File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/site-packages/django/middleware/locale.py", line 24, in init for url_pattern in get_resolver(None).url_patterns: File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/site-packages/django/core/urlresolvers.py", line 402, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/site-packages/django/core/urlresolvers.py", line 396, in urlconf_module self._urlconf_module = import_module(self.urlconf_name) File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 986, in _gcd_import File "", line 969, in _find_and_load File "", line 958, in _find_and_load_unlocked File "", line 673, in _load_unlocked File "", line 665, in exec_module File "", line 222, in _call_with_frames_removed File "/home/cegprakash/workspace/modelsoftheworld/zavanetwork/urls.py", line 33, in url(r'^api/', include('social.urls')), File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/site-packages/django/conf/urls/init.py", line 33, in include urlconf_module = import_module(urlconf_module) File "/home/cegprakash/.local/share/virtualenvs/cegprakash-6Wq6Rd61/lib/python3.5/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 986, in _gcd_import File "", line 969, in _find_and_load File "", line 958, in _find_and_load_unlocked File "", line 673, in _load_unlocked File "", line 665, in exec_module File "", line 222, in _call_with_frames_removed File "/home/cegprakash/workspace/myproj/social/urls.py", line 6, in from social.views import * File "/home/cegprakash/workspace/myproj/social/views.py", line 23, in from social.serializers import * File "/home/cegprakash/workspace/myproj/social/serializers.py", line 15, in from social.utils import * File "/home/cegprakash/workspace/myproj/social/utils.py", line 5, in from rest_framework.compat import OrderedDict ImportError: cannot import name 'OrderedDict' [04/Apr/2018 14:20:24]"GET / HTTP/1.1" 500 59

cegprakash avatar Apr 04 '18 14:04 cegprakash

Hey

Did the issue resolved ?

prateektiwari7 avatar Jun 28 '18 06:06 prateektiwari7

In the documentation it is mentioned wrongly that swagger supports all rest frameworks which are 3.5+.

You cannot get swagger 2+ get working with very old rest framework (i.e. 3.5+). I resolved it by downgrading my swagger to very old version (as in my case I couldn't upgrade my rest framework). Note that you've to follow older documentation to setup older version of swagger. Also note that older version of swagger don't have a great UI and great features that it has now.

cegprakash avatar Jun 28 '18 08:06 cegprakash

Thanks brother,

Issued is solved the requirement.txt have old requirements that must be kept old to run this.

prateektiwari7 avatar Jun 29 '18 06:06 prateektiwari7