Saturday 15 March 2014

python - Django url confs won't match -



python - Django url confs won't match -

i cannot life of me figure out why url configurations not point page in django.

i trying access url shown in error message @ bottom (couldn't link escape, sorry)

yelloworangefoxzebra valid imgid, defined correctly in models.

imgapp/urls.py django.conf.urls import patterns, url imgapp import views urlpatterns = patterns('', url(r'^$', views.index, name='index'), url(r'^(?p<imgid>\d+)/$', views.detail, name='detail'), ) views.py def detail(request, given_image_id): image = get_object_or_404(imgappimage, imgid=given_image_id) homecoming render(request, 'imgapp/detail.html', image) detail.html <img src="{{ image.imgfile.url }}" >

the error message out of django is:

page not found (404) request method: request url: http://127.0.0.1:8000/imgapp/yelloworangefoxzebra/ using urlconf defined in thatsite.urls, django tried these url patterns, in order: ^imgapp/ ^$ [name='index'] ^imgapp/ ^(?p<imgid>\d+)/$ [name='detail'] ^imgapp/ ^(?p<pk>\d+)/results/$ [name='results'] ^imgapp/ ^(?p<question_id>\d+)/vote/$ [name='vote'] ^admin/ ^media/(?p<path>.*)$ current url, imgapp/yelloworangefoxzebra/, didn't match of these.

thanks avinash raj above correcting error in regex. i've fixed issues popped in code after fixing that, couple type errors, , posterity have posted right versions of code in question below:

imgapp/urls.py django.conf.urls import patterns, url imgapp import views urlpatterns = patterns('', url(r'^$', views.index, name='index'), url(r'^(?p<inputid>\w+)/$', views.detail, name='detail'), )

i swapped d+ w+, , fixed it! looking digits when needed looking words.

views.py def detail(request, inputid): image = get_object_or_404(imgappimage, imgid=inputid) context = {'image': image} homecoming render(request, 'imgapp/detail.html', context)

i renamed given_image_id clarity inputid, added line defining context, , replaced image context in render call

detail.html <img src="{{ image.imgfile.url }}" >

i had 1 right! shows image it's total size, unfortunately may much larger window, that's next problem solve!

python django

No comments:

Post a Comment