waffle
waffle

Reputation: 41

ImportError: no module named urls but ROOT_URLCONF is correct

I've read through all the similar questions that I could find on google/SO, and most people had an issue with their ROOT_URLCONF being incorrect or missing an init.py.

My project structure is

djangotut/
    polls/
    static/
    templates/
    __init__.py
    manage.py
    settings.py
    urls.py

My project is called djangotut, and there's also a group level called user_myusername_xyz (my place of work has some prefab code we use for project setup, and I've done this many times without running into this problem).

I've tried

ROOT_URLCONF = 'user_myusername_xyz.djangotut.urls'

(this is what our projects' settings.py files default to)

ROOT_URLCONF = 'djangotut.urls'

and

ROOT_URLCONF = 'urls'

I get the ImportError every time, and I know it's that line because the ExceptionValue changes to the string I used there. (ex: "No module named user_myusername_xyz.djangotut.urls").

The urls.py file is there, so why can't settings.py see it?

urls.py

from django.conf.urls import include, patterns, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^apps/username_myusername_xyz/djangotut/',     
    include('djangotut.polls.urls')),
    url(r'^admin/', include('admin.site.urls')),
)

Upvotes: 1

Views: 913

Answers (2)

waffle
waffle

Reputation: 41

The solution was to remove the quotes from 'admin.site.urls.' The quotes are still needed when including URLs from an INSTALLED_APP, but for some reason the admin one doesn't like quotes.

Upvotes: 1

Daniel Petrikin
Daniel Petrikin

Reputation: 198

is user_myusername_xyz a python package? Does that directory have an init.py ? If it doesn't, it shouldn't be in an import path

I'm guessing no, it doesn't, and you need something more like:

ROOT_URLCONF = 'djangotut.urls'

Upvotes: 0

Related Questions