hammygoonan hammygoonan - 22 days ago 11
Python Question

Django Urls with a dot

I'm trying to match a url like:

/api/1.0/page/1


I've got my main
urls.py
file:

urlpatterns = [
url(r'^api/1.0/', include('api_v1.urls')),
]


and then in my
api_v1/urls.py
file:

urlpatterns = [
url(r'^page/(?P<page_id>[0-9]{4})/', views.page),
]


I feel like it should be simple but I can't get it to work.

wim wim
Answer

Your regex enforces 4 character page ids. But your page id is just 1. Perhaps this pattern would work better:

r'^page/(?P<page_id>[0-9]+)/'