reverse function giving me NoReverseMatch exception

41 views
Skip to first unread message

nav

unread,
Aug 29, 2012, 2:24:08 AM8/29/12
to django...@googlegroups.com
Dear Folks,

I have the following view function defined like this:

my_view(request, uuid, backend=None)

nav

unread,
Aug 29, 2012, 2:35:01 AM8/29/12
to django...@googlegroups.com
Sorry got posted before I finished.

Let me start again.

I have a view function defined like this:

my_view(request, uuid, backend=None)

my urls.py have this:

UUID_PATTERN = r'(?P<uuid>[A-Za-z0-9_-]{22})'
BACKEND = r'(?P<backend>[a-z])'

url(r'^my/view/%s/%s/$' % (UUID_PATTERN, BACKEND),
        'my_view', name='my_view_backend'),

url(r'^my/view/%s/$' % UUID_PATTERN,
        'my_view', name='my_view'),

I am reversing using the following syntax:

reverse('my_view_backend', args=['oUEwFLybQJWruvJPmZLtnw', 'mybackend'])

this should match the first pattern but I keep getting a NoReverseMatch exception. I am aware that I am missing something simple but I am not sure what.

TIA,
nav

Sebastian Goll

unread,
Aug 29, 2012, 2:48:36 AM8/29/12
to django...@googlegroups.com
On Tue, 28 Aug 2012 23:35:01 -0700 (PDT)
nav <navani...@gmail.com> wrote:

> BACKEND = r'(?P<backend>[a-z])'

Your BACKEND pattern is only matching single characters. Try

BACKEND = r'(?P<backend>[a-z]+)'

Best wishes,
Sebastian.

nav

unread,
Aug 29, 2012, 3:43:31 AM8/29/12
to django...@googlegroups.com
Thanks Sebastian that worked. Can't believe it was that simple been breaking my head on this for hours!

Cheers,
nav
Reply all
Reply to author
Forward
0 new messages