Thursday, October 13, 2011

Re: StackedLinein and 404 error

As pointed by the error message you are getting, the url you tried did not match any of the urls django is aware of.

For using any Model in the admin, you need to register it with the admin. As evident from your url, you are trying to use a model named Choice under polls app. But you have not registered this model in the admin.

So, in your admin.py you need to add the following line:

admin.site.register(Choice)

This line should be added after or before the following line:

admin.site.register(Poll, PollAdmin)

Hopefully this should work if everything else is correct.

Thanks,
Akshar


On Sun, Oct 9, 2011 at 7:45 AM, EdgarAllenPoe <tomstoutster@gmail.com> wrote:
Working on django tutorial here: https://docs.djangoproject.com/en/dev/intro/tutorial02/
and I am stuck where they start the instructions about Stackedlnline.
I keep getting the following error:

Page not found (404)
Request Method:         GET
Request URL:    http://127.0.0.1:8000/admin/polls/choice/add/

Using the URLconf defined in mysite.urls, Django tried these URL
patterns, in this order:

   ^admin/ ^$ [name='index']
   ^admin/ ^logout/$ [name='logout']
   ^admin/ ^password_change/$ [name='password_change']
   ^admin/ ^password_change/done/$ [name='password_change_done']
   ^admin/ ^jsi18n/$ [name='jsi18n']
   ^admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$
   ^admin/ ^(?P<app_label>\w+)/$ [name='app_list']
   ^admin/ ^polls/poll/
   ^admin/ ^auth/group/
   ^admin/ ^sites/site/
   ^admin/ ^auth/user/

The current URL, admin/polls/choice/add/, didn't match any of these.

My admin.py and urls.py are shown below

Can some one take a look and tell me where I am going wrong?

*****admin.py******

from polls.models import Poll
from polls.models import Choice
from django.contrib import admin

class ChoiceInline(admin.StackedInline):
   model = Choice
   extra = 3

class PollAdmin(admin.ModelAdmin):
   fieldsets = [
       (None,               {'fields': ['question']}),
       ('Date information', {'fields': ['pub_date'], 'classes':
['collapse']}),
   ]
   inlines = [ChoiceInline]

admin.site.register(Poll, PollAdmin)

*****urls.py*****

from django.conf.urls.defaults import *

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

urlpatterns = patterns('',
   # Example:
   # (r'^mysite/', include('mysite.foo.urls')),

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

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

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


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

No comments:

Post a Comment