How Do I Use A Decimal Number In A Django URL Pattern? How Do I Use A Decimal Number In A Django URL Pattern? django django

How Do I Use A Decimal Number In A Django URL Pattern?


It can be something like

urlpatterns = patterns('',   (r'^item/value/(?P<value>\d+\.\d{2})/$', 'myapp.views.byvalue'),   ... more urls)

url should not start with slash.

in views you can have function:

def byvalue(request,value='0.99'):    try:        value = float(value)    except:        ...


I don't know about Django specifically, but this should match the URL:

r"^/item/value/(\d+\.\d+)$"


If the values to be accepted are only $0.01 or $0.05, the harto's pattern may be specified like this:

r"^/item/value/(\d\.\d{2})$"