簡體   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