made_in_india
made_in_india

Reputation: 2279

django "Exception Value: No module named urls" for admin site

I am django newbie , trying to follow a tutorial. When I am trying to access django administration site

        http://127.0.0.1:8000/admin/

it giving the error "Exception Value: No module named urls" for the below code

    #uls.py
    from django.conf.urls import *
    from mysite.views import *
    # Uncomment the next two lines to enable the admin:

    # from django.contrib import admin
    # admin.autodiscover()
    #TODO ADD LIST OF URL
    urlpatterns = patterns('',
        (r'^home\/?$',get_homepage),
        (r'^admin\/?$',include('django.contrib.admin.urls')),
    )

I have tried multiple solution aviable on stackover flow @last publishing the issue get it resolved

    #settings.py
    ROOT_URLCONF = 'mysite.urls'
    # Python dotted path to the WSGI application used by Django's runserver.
    WSGI_APPLICATION = 'mysite.wsgi.application'
    TEMPLATE_DIRS = (
        '/home/abuzzar/djcode/mysite/mysite/template',
        # Put strings here, like "/home/html/django_templates" or                 "C:/www/django/templates".
            # Always use forward slashes, even on Windows.
            # Don't forget to use absolute paths, not relative paths.
        )

        INSTALLED_APPS = (
            'django.contrib.auth',
            'django.contrib.contenttypes',
            #'django.contrib.sessions',
            #'django.contrib.sites',
            #'django.contrib.messages',
            #'django.contrib.staticfiles',
            'mysite.jobpost',
            'django.contrib.admin',
            # Uncomment the next line to enable the admin:
            # 'django.contrib.admin',
            # Uncomment the next line to enable admin documentation:
            # 'django.contrib.admindocs',
        )

error : http://pastebin.com/RMvzPd61

i tried the solution : Django 1.5.1 'ImportError: No module named urls' when running tests but did not worked.

Upvotes: 1

Views: 4543

Answers (3)

foszter
foszter

Reputation: 179

karthikr's answer is the first thing to check. Also make sure your project folder is included in sys.path. I'm trying this while using a development environment (Aptana), and have had to change the workspace folder name to avoid command-line issues (the default workspace folder generated by Aptana is chock-full of spaces: 'Aptana Studio 3 Workspace'). Thus the framework was looking in a folder that didn't exist.

A dumb oversight, to be sure, but if you're as new at this as I am it's at least worth looking at.

Upvotes: 0

virtuexru
virtuexru

Reputation: 888

Also, be sure not to leave your /admin URL named /admin. I would change it. Otherwise someone can try to brute-force your login or look for holes in your backend. :)

Upvotes: 0

karthikr
karthikr

Reputation: 99620

To include admin urls, use this:

from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
)

Or, to fix your issue, add site between admin and urls

(r'^admin\/?$',include('django.contrib.admin.site.urls'))

On a general note, I would revisit the URL pattern. ^admin\/?$ should not have the $ at the end since you are including another url conf.

Also, ^admin/ should be sufficient

Upvotes: 1

Related Questions