S.Xia
S.Xia

Reputation: 35

regular expression in urls. py in django 2.0

How can I write these two urls including their regular expression in django 2.0? Huge thanks.

url(r'^page/(?P<id>\S+_[0-9]{3,})', views.pageinfo, name="page"),
url(r'^something/(?P<id>\S+)/', views.jsoninfo, name="testinfo2"),

Upvotes: 2

Views: 1627

Answers (2)

lmiguelvargasf
lmiguelvargasf

Reputation: 69675

In Django 2+, you don't need to use regular expressions in your urls, you can use path as follows:

path('page/<int:id>/', views.pageinfo, name="page"),
path('something/<int:id>/', views.jsoninfo, name="testinfo2"),

Upvotes: 3

FlipperPA
FlipperPA

Reputation: 14311

In Django 2.0, url has simply be renamed re_path and moved into django.urls:

from django.urls import re_path

re_path(r'^page/(?P<id>\S+_[0-9]{3,})', views.pageinfo, name="page"),
re_path(r'^something/(?P<id>\S+)/', views.jsoninfo, name="testinfo2"),

Details here: https://docs.djangoproject.com/en/2.0/topics/http/urls/#using-regular-expressions

Upvotes: 0

Related Questions