2

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"),
1
  • This should work in django 2.0 Commented Jun 29, 2018 at 20:02

2 Answers 2

3

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"),
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.