Adding YouTube video id to url

19 views
Skip to first unread message

Sithembewena Lloyd Dube

unread,
Aug 10, 2013, 4:31:56 PM8/10/13
to django...@googlegroups.com
Hi,

I am using the YouTube API to fetch video data and display it on a web page. As part of the html template I have an anchor tag with an href directing to my Django 1.5 app. as follows:

<a href="{% url 'find_music:watch' video_id=video.video_id %}">

The url definition in urls.py is as follows:

url(r'^(?P<video_id>\w+)$', 'find_music.views.watch', name='watch'),

When I load the page, I get a NoReverseMatch exception as follows:

Reverse for 'watch' with arguments '()' and keyword arguments '{u'video_id': 'D-dNA0NwLSw'}' not found.

What could I be missing?

Thanks.

--
Regards,
Sithu Lloyd Dube

Sithembewena Lloyd Dube

unread,
Aug 10, 2013, 4:35:18 PM8/10/13
to django...@googlegroups.com
P.S: The view looks like the following:

def watch(request, video_id):
return HttpResponse("This is the watch page for ...") % video_id

Sithembewena Lloyd Dube

unread,
Aug 10, 2013, 4:36:09 PM8/10/13
to django...@googlegroups.com
P.S: The view looks like the following:

def watch(request, video_id):
return HttpResponse("This is the watch page for %s") % video_id


On Sat, Aug 10, 2013 at 10:31 PM, Sithembewena Lloyd Dube <zeb...@gmail.com> wrote:

Sithembewena Lloyd Dube

unread,
Aug 10, 2013, 4:59:06 PM8/10/13
to django...@googlegroups.com
Sorted. I got owned by regex :-/

In urls.py, it should be:

url(r'^watch/(?P<video_id>[\w{}.-]{1,40})/$', 'find_music.views.watch', name='watch'),


Thanks.
Reply all
Reply to author
Forward
0 new messages