簡體   English   中英

帶有參數的 Django URL 不起作用

[英]Django URL with parameters not working

我正在嘗試使用將參數傳遞給 Django 中的 URL,但我不斷收到此錯誤:

 Page not found (404)
Request Method: GET
Request URL:    http://localhost:8000/%7B%25%20url%20review%20review_id%3D3%20%25%7D
Using the URLconf defined in soundclinic.urls, Django tried these URL patterns, in this order:

[name='index']
login/ [name='login']
register/ [name='register']
create_user [name='create_user']
<int:review_id>/review/ [name='review']
admin/
main/
The current path, {% url review review_id=3 %}, didn't match any of these.

我關注的鏈接有一個類似上面的標簽: {% url review review_id=3 %}

我不確定我沒有包括什么,因為看起來我正確地寫出了 url 標簽,而且 urls.py 似乎也被正確配置。

手動輸入 URL 會調用正確的 views.py 函數,因此它只與我的 urls.py 文件有關。

正如 kszl 已經說過的,您必須在 URL 名稱周圍使用“'”。

{% url 'review' review_id=3 %}

它假設您在某個 url.py 中有一個名為“review”的 URL。 似乎確實如此,因為我們可以看到

<int:review_id>/review/ [name='review']

在您的日志消息中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM