[Fixed]-Regex django url

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.

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

Leave a comment