繁体   English   中英

在视图 django 中通过 url 传递参数时找不到页面错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM