2

I am trying to get the admin site to work for my Django Project. I am following this tutorial https://docs.djangoproject.com/en/1.4/intro/tutorial02/ and I am using Django 1.4.

Urls.py:

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

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

urlpatterns = patterns('',
    (r'^$', include('polls.urls')),
    # Examples:
    # url(r'^$', 'Blog.views.home', name='home'),
    # url(r'^Blog/', include('Blog.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(admin.site.urls)),
)

The settings.py is:

 DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'dev.db',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

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

)

The error msg i get is:

DoesNotExist at /admin/
Site matching query does not exist.
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/
Django Version: 1.4
Exception Type: DoesNotExist
Exception Value:    
Site matching query does not exist.
Exception Location: /Users/IMAC/work3/env/lib/python2.7/site-packages/django/db/models/query.py in get, line 366
Python Executable:  /Users/IMAC/work3/env/bin/python
Python Version: 2.7.1
Python Path:    
['/Users/IMAC/work3/Blog',
 '/Users/IMAC/work3/env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/Users/IMAC/work3/env/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
 '/Users/IMAC/work3/env/lib/python27.zip',
 '/Users/IMAC/work3/env/lib/python2.7',
 '/Users/IMAC/work3/env/lib/python2.7/plat-darwin',
 '/Users/IMAC/work3/env/lib/python2.7/plat-mac',
 '/Users/IMAC/work3/env/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/IMAC/work3/env/Extras/lib/python',
 '/Users/IMAC/work3/env/lib/python2.7/lib-tk',
 '/Users/IMAC/work3/env/lib/python2.7/lib-old',
 '/Users/IMAC/work3/env/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/IMAC/work3/env/lib/python2.7/site-packages']

Not Sure what is the problem? Need some guidance. Would appreciate any help.

lakshmen
  • 28,346
  • 66
  • 178
  • 276

3 Answers3

2

settings.py :

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'data.db',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}


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

urls.py:

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


from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

    url(r'^admin/', include(admin.site.urls)),
)

run syncdb to create the db and a user. Then it should work.

lciamp
  • 675
  • 1
  • 9
  • 19
  • Firstly, thanks for helping. I double-checked the errors and I have also posted the urls.py above.. have a look... – lakshmen Jun 05 '12 at 02:55
  • You need to run python manage.py syncdb. So you can create the database and create a superuser. Im gonna change my answer to show you. – lciamp Jun 05 '12 at 02:59
  • if you ran it before you added the admin, you might want to delete the database and re-run syncdb. Also, are you using a complier? – lciamp Jun 05 '12 at 03:17
  • you need a superuser, you create one when you run syncdb, it's the name and password you use to log into the admin page. – lciamp Jun 05 '12 at 03:25
  • When I deleted the db and recreated it, it asks me this: You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): When i type yes, it doesn't allow to create one... Why is that so? – lakshmen Jun 05 '12 at 03:29
  • What does the error say? and are you using a complier? I've herd pyCharm has problems with syncdb when running python 2.7. – lciamp Jun 05 '12 at 03:35
  • http://stackoverflow.com/questions/10891255/adding-a-database-to-the-django-project-using-sqlite3 – lakshmen Jun 05 '12 at 03:38
  • I just ran it in terminal using 2.7 and im getting the same error. I normally use 2.6.6. Now I wanna know what's wrong. I'll mess around and let you know. – lciamp Jun 05 '12 at 03:49
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/12135/discussion-between-lakesh-and-lciamp) – lakshmen Jun 05 '12 at 03:50
2

I had the same issue during the tutorial. You mention a Python error when trying to create a super user, is it the one below?

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

This has to do with your terminal's locale settings. See here for a SO solution. Run the two export commands mentioned there, delete your database file, run 'python manage.py syncdb' to create the database again, enter 'yes' to create super-user. This shouldnt give you an error anymore and you should now be able to access the admin site on localhost.

Community
  • 1
  • 1
phillchill
  • 116
  • 1
  • 4
1

Late reply..

But I got the fix for this problem from here

http://satishgandham.com/2012/04/error-whil-creating-super-user-in-django1-4-on-mac/

Edited Based on the comment


This problem was rectified by running this command in terminal before adding the user

export LANG="en_US.UTF-8"

I’m guessing this character encoding problem while running syncdb is the reason for the following error while accessing admin section of django1.4

anoop
  • 3,229
  • 23
  • 35
  • This is basically a link-only answer, which is not something we want to see on Stack Overflow. Please explain what it is about the linked page that answers the poster's question, including some code demonstrating the fix. – the Tin Man Dec 30 '12 at 04:48