Skip to content

"urls doesn't look like a module path" for settings.ROOT_URLCONF #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ckcollab opened this issue Mar 8, 2016 · 9 comments
Closed

Comments

@ckcollab
Copy link

ckcollab commented Mar 8, 2016

Heyoo, thanks so much for releasing this!

I seem to be having a problem based on this setting:
ROOT_URLCONF = 'urls'

  File "/Users/eric/.virtualenvs/image_first/lib/python3.5/site-packages/rest_framework_docs/views.py", line 17, in get_context_data
    docs = ApiDocumentation()
  File "/Users/eric/.virtualenvs/image_first/lib/python3.5/site-packages/rest_framework_docs/api_docs.py", line 12, in __init__
    root_urlconf = import_string(settings.ROOT_URLCONF)
  File "/Users/eric/.virtualenvs/image_first/lib/python3.5/site-packages/django/utils/module_loading.py", line 18, in import_string
    six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])
  File "/Users/eric/.virtualenvs/image_first/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/eric/.virtualenvs/image_first/lib/python3.5/site-packages/django/utils/module_loading.py", line 15, in import_string
    module_path, class_name = dotted_path.rsplit('.', 1)
ImportError: urls doesn't look like a module path

Changing to this works:
ROOT_URLCONF = 'src.urls'

@andrewyoung1991
Copy link
Contributor

the path to your urlconf should be relative to the manage.py file (e.g. the BASE_DIR setting defined in settings.py). so if your project is named src and your directory structure is standard:

src/
  manage.py
  src/
    settings.py
    wsgi.py
    urls.py

then your ROOT_URLCONF setting should be 'src.urls'.

this is a standard Django setting and is the default path generated by the django-admin.py startproject command.

I hope this answers your question.

@ambivalentno
Copy link
Contributor

I have to note that it's not a "standard", but a "default", as there's an option to provide a template for startproject command.
For instance, I've got such project layout:

project/
├── apps
│   ├── core
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── __init__.py
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   └── __init__.py
│   │   ├── models.py
│   │   ├── serializers.py
│   │   ├── urls.py
│   │   └── views.py
│   └── __init__.py
├── conf
│   ├── base.py
│   ├── __init__.py
│   └── local.example.py
├── db
│   └── development.db
├── __init__.py
├── manage.py
├── templates
│   └── base.html
├── urls.py
└── wsgi.py

So, I'm researching this at the moment, as I've got urls in the same place as manage.py file :)

@ambivalentno
Copy link
Contributor

looks like this works (in api_docs.py):

try:
            root_urlconf = import_string(settings.ROOT_URLCONF)
        except ImportError:
            from importlib import import_module
            root_urlconf = import_module(settings.ROOT_URLCONF)

@ambivalentno
Copy link
Contributor

pullrequest #73

@manosim
Copy link
Owner

manosim commented Mar 22, 2016

@andrewyoung1991 Does #73 solve the problem for you too?

@andrewyoung1991
Copy link
Contributor

works for me.

@manosim
Copy link
Owner

manosim commented Mar 22, 2016

Great! Let's merge it in!

@ckcollab
Copy link
Author

Thanks for all the work on this boys 👯

@manosim
Copy link
Owner

manosim commented Mar 25, 2016

@ckcollab @ambivalentno Version 0.0.9 is now on PyPI 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants