On Jul 30, 2017 12:06 AM, "ron_w_add via Django users" <
django-users@googlegroups.com> wrote:

I have started writing a page to to display a photo. This page correctly
display the photo data (nb. no photo added yet) as well as the ‘Invalid
item ID’ message if an invalid value has been requested. The HTML code is
in ‘photos.html’ is as follows:

<snip>


I am now trying to start testing the above function by using the following
test function in tests_views.py:


class PhotosByLocationIndexViewTests(TestCase):

     """

     testing 'def photo(requeset)'

     """

     def test_for_no_photos_in_photos(self):

           # 'photourl' is in 'wlp_app/urls.py'

           response = self.client.get(reverse('photourl'))




The above line is your issue. See below.


The ‘photourl’ name that is called by the ‘reverse’ function above is in
the urls.py:


urlpatterns = [

     url(r'^$', views.index, name='indexurl'),

     url(r'^photo/(?P<photo_id>[0-9]+)/$', views.photo, name='photourl')

]


Per the urls.py above, you need to provide a value for the photo_id to
reverse() as an arg or kwarg, otherwise Django has no way to know which
photo you are referring to, and therefore can't generate the URL.

See the following for proper usage of reverse() with examples.

https://docs.djangoproject.com/en/1.11/ref/urlresolvers/#reverse

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVzNZ5HkN5h_qFDcHVOvLosO1mh9K1VrzbaUP%2BgAn1PsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to