0

I am newbie to django.I m using python 2.6 with django 1.3v I am trying to create a simple blog application.When I access the http://127.0.0.1:8000/admin/ I'm getting the error No module named urls.I gave this url(r'^admin/', include('django.contrib.admin.urls')) in urls.py.

urls.py

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^mysite/', include('mysite.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
     url(r'^admin/', include('django.contrib.admin.urls')),
)

settings.py

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

models.py

   from django.db import models
   from django.contrib import admin

   class BlogPost(models.Model):
     title=models.CharField(max_length=150)
     body=models.TextField()
     timestamp=models.DateTimeField()

   admin.site.register(BlogPost)

Error:

ImportError at /admin/

No module named urls

Request Method:     GET
Request URL:    http://127.0.0.1:8000/admin/
Django Version:     1.3
Exception Type:     ImportError
Exception Value:    

No module named urls

Exception Location:     /usr/local/lib/python2.6/dist-packages/django/utils/importlib.py in import_module, line 35
Python Executable:  /usr/bin/python
Python Version:     2.6.6
Python Path:    

['/home/bharathi/development/python/mysite',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/usr/lib/python2.6/lib-old',
 '/usr/lib/python2.6/lib-dynload',
 '/usr/local/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages',
 '/usr/lib/pymodules/python2.6',
 '/usr/lib/pymodules/python2.6/gtk-2.0']                                       

Any pointers?

6
  • 1
    Check INSTALLED_APPS, it should have 'django.contrib.admin'. Commented Aug 27, 2011 at 12:10
  • Yes.django.contrib.admin uncommented! Commented Aug 27, 2011 at 12:12
  • Can you paste the code in your urls.py ? Commented Aug 27, 2011 at 12:17
  • 2
    Try uncommenting # from django.contrib import admin # admin.autodiscover() Commented Aug 27, 2011 at 12:25
  • Uncommented.But I am getting No module named urls Commented Aug 27, 2011 at 12:31

2 Answers 2

1

Thanks.There was improper indentation.I fixed it.

Sign up to request clarification or add additional context in comments.

2 Comments

Always good to "show invisibles" in your editor when working with Python, if you have such an option.
Tabs or spaces, pick one. If in doubt, use spaces. ... Shoot, if in doubt, do what PEP 8 tells you.
0

Did you enable django.contrib.admin in your settings.py INSTALLED_APPS tuple?

Django will only know of python modules (also called 'django app's in django terminology) if you have state them in the INSTALLED_APPS tuple in your django project's settings.py file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.