Problem in Part2 of the tutorial "DoesNotExist at /admin/"

2,407 views
Skip to first unread message

igalic

unread,
May 17, 2011, 1:53:10 PM5/17/11
to Django users
Hi,

I went through the first part of the tutorial without problems, but
when trying to turn on the admin app in tutorial 2, I got this error
page with the message stated in subject line.

Here's more info:

Django: latest version from the trunk
Python: 2.6.1
OS: OSX 10.6.7

Here's the info it gives me:

DoesNotExist at /admin/
Site matching query does not exist.


Traceback:
File "/Users/nightition/Development/django-trunk/django/core/handlers/
base.py" in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File "/Users/nightition/Development/django-trunk/django/contrib/admin/
sites.py" in wrapper
213. return self.admin_view(view, cacheable)(*args,
**kwargs)
File "/Users/nightition/Development/django-trunk/django/utils/
decorators.py" in _wrapped_view
91. response = view_func(request, *args,
**kwargs)
File "/Users/nightition/Development/django-trunk/django/views/
decorators/cache.py" in _wrapped_view_func
77. response = view_func(request, *args, **kwargs)
File "/Users/nightition/Development/django-trunk/django/contrib/admin/
sites.py" in inner
195. return self.login(request)
File "/Users/nightition/Development/django-trunk/django/views/
decorators/cache.py" in _wrapped_view_func
77. response = view_func(request, *args, **kwargs)
File "/Users/nightition/Development/django-trunk/django/contrib/admin/
sites.py" in login
330. return login(request, **defaults)
File "/Users/nightition/Development/django-trunk/django/utils/
decorators.py" in _wrapped_view
91. response = view_func(request, *args,
**kwargs)
File "/Users/nightition/Development/django-trunk/django/views/
decorators/cache.py" in _wrapped_view_func
77. response = view_func(request, *args, **kwargs)
File "/Users/nightition/Development/django-trunk/django/contrib/auth/
views.py" in login
58. current_site = get_current_site(request)
File "/Users/nightition/Development/django-trunk/django/contrib/sites/
models.py" in get_current_site
92. current_site = Site.objects.get_current()
File "/Users/nightition/Development/django-trunk/django/contrib/sites/
models.py" in get_current
25. current_site = self.get(pk=sid)
File "/Users/nightition/Development/django-trunk/django/db/models/
manager.py" in get
132. return self.get_query_set().get(*args, **kwargs)
File "/Users/nightition/Development/django-trunk/django/db/models/
query.py" in get
349. % self.model._meta.object_name)


Does anyone have an idea of what I'm doing wrong?

Needless to say, these are my first steps with Django and I don't
really have an idea where to go from here - I've searched google, the
list.. no luck.

Thanks,
Ivan

Gabriel Gunderson

unread,
May 18, 2011, 2:34:21 AM5/18/11
to django...@googlegroups.com
On Tue, May 17, 2011 at 11:53 AM, igalic <ivan....@gmail.com> wrote:
> I went through the first part of the tutorial without problems, but
> when trying to turn on the admin app in tutorial 2, I got this error
> page with the message stated in subject line.
>
> Here's more info:
>
> Django: latest version from the trunk
> Python: 2.6.1
> OS: OSX 10.6.7
>
> Here's the info it gives me:
>
> DoesNotExist at /admin/
> Site matching query does not exist.


It looks like it's related to the sites framework:
http://docs.djangoproject.com/en/dev/ref/contrib/sites/

I'd have a look at what's in my settings file for SITE_ID and take it
from there.
http://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SITE_ID

Let us know if you don't figure it out.


Best,
Gabe

Ivan Galic

unread,
May 18, 2011, 11:39:55 AM5/18/11
to django...@googlegroups.com

Thanks; unfortunately I haven't been able to move much further along.
The SITE_ID setting is set to 1, which was automatically generated. My project doesn't reference it anywhere. The docs say the default
is "not defined" so I tried deleting it, but then it gave me another error (complaining it wasn't defined). Setting it to 0 (a value I thought
could be sensible) didn't work either.
Checking the local variables in the exception stack trace, it seems the ID is passed properly (at the place where it crashes, in

django/db/models/query.py in get

the "pk" parameter is 1, which is set at one point below in the stack from "sid" (which I assume is
site_id).

The code that crashes is this:

• if self.query.can_filter():
• clone = clone.order_by()
• num = len(clone)
• if num == 1:
• return clone._result_cache[0]
• if not num:
• raise self.model.DoesNotExist("%s matching query does not exist."
• % self.model._meta.object_name) ...
• raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameters were %s"
• % (self.model._meta.object_name, num, kwargs))

In this case, 'num' is nil, and self.model._meta.object_name is 'Site'.

That's all I've been able to dig out; I'd appreciate any further help.

I'm surprised I ran into this problem because I was just strictly following the tutorial, and I've basically just added some 10 lines of code
to the project. I don't understand what could have gone wrong.

Thanks,
Ivan

>
>
> Best,
> Gabe
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

Ivan Galic

unread,
May 18, 2011, 12:07:21 PM5/18/11
to django...@googlegroups.com
Ok, I got it to work.

Since the exception said " 'Site' matching query does not exist", and the docs said something about the SITE_ID describing the site in the django_site database table, I went ahead and took a look at my (sqlite) database. The django_site table was empty, so I added a row with id==1 (the same that I have in settings.py) and then it worked.

However, I still don't understand what went wrong. Who should be responsible for putting that table row in the database? I ran syncdb several times (to make sure I didn't miss it :) ), but it didn't help.

Ivan

On May 18, 2011, at 8:34 AM, Gabriel Gunderson wrote:

Reply all
Reply to author
Forward
0 new messages