I am using Django 2.1.4 I Want to Pass a parameter like question_id in the url but i just get 404 .
This is My Code :
urls.py :
urlpatterns = [
path('index',views.index , name='index'),
path('index/(?P<question_id>[0-9])',views.detail , name='detail'),
]
and this is my :
view.py
def index(request,):
return HttpResponse("Welcome To My Page")
def detail(request, question_id):
return HttpResponse("new Page" + str(question_id))
When I Enter http://127.0.0.1:8000/polls/index/12 in the url , i just get 404 .
With Django 2.1.4 the path
method can parse params in the URL with the following syntax:
urlpatterns = [
path('index',views.index , name='index'),
path('index/<int:question_id>', views.detail , name='detail'),
]
If you want to stick to the good old regex, you should probably change your 'detail' view to
path('index/(?P<question_id>[0-9]+/$)',views.detail , name='detail')
See also this article for more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.