user7795844
user7795844

Reputation:

Django regex not matching

I have trouble matching urls using regex in Python/Django.

Here is the url it needed to fetch

http://127.0.0.1:8000/blog/2017/11/3/1/

Here is the code:

from django.conf.urls import url
from blog import views

app_name = 'blog'
urlpatterns = [
    url(r'^blog/$', views.blog, name='archive'),
    url(r'^blog/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/(?P<id>[0-9]+)/$', views.blog_article, name='blog_article'),
] # regex

Upvotes: 1

Views: 186

Answers (1)

knbk
knbk

Reputation: 53649

The day 3 does not match the capturing group (?P<day>[0-9]{2}). Either change it to 03 or change the group to (?P<day>[0-9]{1,2}).

Upvotes: 4

Related Questions