15

Hello I have a url and I want to match the uuid the url looks like this:

/mobile/mobile-thing/68f8ffbb-b715-46fb-90f8-b474d9c57134/

urlpatterns = patterns("mobile.views",
    url(r'^$', 'something_cool', name='cool'),
    url(r'^mobile-thing/(?P<uuid>[.*/])$', 'mobile_thing', name='mobile-thinger'),
)

but this doesn't work at all. My corresponding view is not being called. I tested so many variations...ahw

but url(r'^mobile-thing/', 'mobile_thing', name='mobile-thinger') works like a charm but no group...

Nishant Upadhyay
  • 639
  • 7
  • 20
Jurudocs
  • 8,595
  • 19
  • 64
  • 88

2 Answers2

33

The [.*/] expression only matches one character, which can be ., * or /. You need to write instead (this is just one of many options):

urlpatterns = patterns("mobile.views",
    url(r'^$', 'something_cool', name='cool'),
    url(r'^mobile-thing/(?P<uuid>[^/]+)/$', 'mobile_thing', name='mobile-thinger'),
)

Here, [^/] represents any character but /, and the + right after matches this class of character one or more times. You do not want the final / to be in the uuid var, so put it outside the parentheses.

IAbstract
  • 19,551
  • 15
  • 98
  • 146
Nicolas Cortot
  • 6,591
  • 34
  • 44
  • thanks a lot...this does not call my view function...i also tried so many variations...could it be a problem that this urls are included into another urls? – Jurudocs Jan 02 '14 at 17:59
  • 1
    *How* is it being included? Show that code. The problem is almost certainly there. – Daniel Roseman Jan 02 '14 at 18:18
2

Try this regex instead:

\/mobile-thing\/(?P<uuid>.*)\/$

So it'd be:

urlpatterns = patterns("mobile.views",
    url(r'^$', 'something_cool', name='cool'),
    url(r'\/mobile-thing\/(?P<uuid>.*)\/$', 'mobile_thing', name='mobile-thinger'),
)
K DawG
  • 13,287
  • 9
  • 35
  • 66
  • thanks..i missed to say that the regex is insite of an included url...this does matter does it? – Jurudocs Jan 02 '14 at 17:58
  • ".*" is all characters and will include "/" when it is not the ending character. So "/asdffadd/asdfdfsadf/" = "asdffadd/asdfdfsadf" – Sean Oct 20 '16 at 16:52