[英]page not found error while passing paarmeter through url in view django
我是 python django 的新手。 我在传递参数以通过 django 中的 URL 查看时遇到问题。 代码:views.py
from django.shortcuts import render
from django.http import HttpResponse
def hello(request):
text = "HEllo"
return HttpResponse(text)
def viewArticle(request, articleId):
text = "HEllo : %d"%articleId
return HttpResponse(text)
urls.py
from django.conf.urls import url
from django.urls import path,include
from myapp import views
urlpatterns = [
path('hello/',views.hello,name='hello'),
path('article/(\d
+)/',views.viewArticle,name='article'),
]
您需要像这样更改您的网址:
path('article/<int:articleId>/',views.viewArticle,name='article'),
希望这项工作!
这里你正在使用path 。 路径使用没有正则表达式的路由。
您需要将网址更改为,
path('article/<int:articleId>/',views.viewArticle,name='article'),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.