日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python项目NoReverseMatch: Reverse for ‘topic‘ with arguments ‘(‘‘,)‘ not found解决方法

發布時間:2025/4/5 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python项目NoReverseMatch: Reverse for ‘topic‘ with arguments ‘(‘‘,)‘ not found解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

      • 遇到的問題
      • 解決方法
      • 參考

遇到的問題

今天在閱讀《python編程-從入門到實踐》這本書,并且課本上的項目之時,在第18章:將顯示所有主題的頁面中的每個主題都設置為鏈接的代碼中,遇到了錯誤

File "D:\user\文檔\python\python_work\learning_log\ll_env\lib\site-packages\django\urls\base.py", line 86, in reversereturn resolver._reverse_with_prefix(view, prefix, *args, **kwargs)File "D:\user\文檔\python\python_work\learning_log\ll_env\lib\site-packages\django\urls\resolvers.py", line 694, in _reverse_with_prefixraise NoReverseMatch(msg) django.urls.exceptions.NoReverseMatch: Reverse for 'topic' with arguments '('',)' not found. 1 pattern(s) tried: ['topics/(?P<topic_id>\\d+)/$']

這個問題在于筆者修改了topics.html文件,下面是出錯的版本:問題出在 鏈接href那里, 需要的是topic.id,由于筆者手誤,寫成了tipic_id,導致反向匹配找不到。

{% extends "learning_logs/base.html" %} {% block content %}<p>Topics</p><ul>{% for topic in topics %}<li><a href="{% url 'learning_logs:topic' topic_id %}">{{ topic }}</a></li>{% empty %}<li>No topics have been added yet.</li>{% endfor %}</ul>{% endblock content %}

當點擊topics時,就會出現問題:

解決方法

檢查自己寫的代碼,和書本上進行對照,一般是寫錯了某個地方。筆者將topic_id改為topic.id后,解決了問題。

正確的代碼:
topics.html

{% extends "learning_logs/base.html" %} {% block content %}<p>Topics</p><ul>{% for topic in topics %}<li><a href="{% url 'learning_logs:topic' topic.id %}">{{ topic }}</a></li>{% empty %}<li>No topics have been added yet.</li>{% endfor %}</ul>{% endblock content %}

參考

[1]https://blog.csdn.net/qq_20379795/article/details/80889068

總結

以上是生活随笔為你收集整理的python项目NoReverseMatch: Reverse for ‘topic‘ with arguments ‘(‘‘,)‘ not found解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。