Skip to content

Commit 694a3e1

Browse files
committed
Use Django's module loading rather than __import__
__import__ doesn't deal well with dotted paths, in my instance my root url conf is in a few levels "appname.config.urls". unfortunately, for __import__ this means that just `appname` is imported, but `config.urls` is loaded and no other modules in between are usable. Switching to Django's `import_string` method allows importing the final module in the path string, in my case the equivalent would be `from appname.config import urls`.
1 parent 112674b commit 694a3e1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

rest_framework_docs/api_docs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.conf import settings
22
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern
3+
from django.utils.module_loading import import_string
34
from rest_framework.views import APIView
45
from rest_framework_docs.api_endpoint import ApiEndpoint
56

@@ -8,7 +9,7 @@ class ApiDocumentation(object):
89

910
def __init__(self):
1011
self.endpoints = []
11-
root_urlconf = __import__(settings.ROOT_URLCONF)
12+
root_urlconf = import_string(settings.ROOT_URLCONF)
1213
if hasattr(root_urlconf, 'urls'):
1314
self.get_all_view_names(root_urlconf.urls.urlpatterns)
1415
else:

0 commit comments

Comments
 (0)