Python “的反面;新的“U条目”;找不到
正在学习Python速成课程,并完全挂断了此错误:Python “的反面;新的“U条目”;找不到,python,django,Python,Django,正在学习Python速成课程,并完全挂断了此错误: NoReverseMatch at /new_entry/1/ Reverse for 'new_entry' with arguments '('',)' not found. 1 pattern(s) tried: ['new_entry/(?P<topic_id>[0-9]+)/$'] Request Method: GET Request URL: http://127.0.0.1:8000/new_entry/1/ Dja
NoReverseMatch at /new_entry/1/
Reverse for 'new_entry' with arguments '('',)' not found. 1 pattern(s) tried: ['new_entry/(?P<topic_id>[0-9]+)/$']
Request Method:
GET
Request URL:
http://127.0.0.1:8000/new_entry/1/
Django Version:
3.0.4
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'new_entry' with arguments '('',)' not found. 1 pattern(s) tried: ['new_entry/(?P<topic_id>[0-9]+)/$']
Exception Location:
C:\Users\KentSurface\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 677
Python Executable:
C:\Users\KentSurface\AppData\Local\Programs\Python\Python38-32\python.exe
Python Version:
3.8.2
Python Path:
['C:\\Users\\KentSurface\\PycharmProjects\\learning_log',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
Server time:
Thu, 19 Mar 2020 19:40:21 +0000
Error during template rendering
In template C:\Users\KentSurface\PycharmProjects\learning_log\learning_logs\templates\learning_logs\base.html, error at line 0
Reverse for 'new_entry' with arguments '('',)' not found. 1 pattern(s) tried: ['new_entry/(?P<topic_id>[0-9]+)/$']
1
<p>
2
<a href="{% url 'learning_logs:index' %}">Learning Log</a> -
3
<a href="{% url 'learning_logs:topics' %}">Topics</a>
4
</p>
5
6
{% block content %}{% endblock %}
7
NoReverseMatch at/new_entry/1/
找不到参数为“(“”,)”的“new_entry”的反向项。尝试了1个模式:[“新条目/(?P[0-9]+)/$”]
请求方法:
收到
请求URL:
http://127.0.0.1:8000/new_entry/1/
Django版本:
3.0.4
异常类型:
诺维塞马奇
异常值:
找不到参数为“(“”,)”的“new_entry”的反向项。尝试了1个模式:[“新条目/(?P[0-9]+)/$”]
异常位置:
C:\Users\KentSurface\AppData\Local\Programs\Python38-32\lib\site packages\django\url\resolvers.py in\u reverse\u带前缀,第677行
Python可执行文件:
C:\Users\KentSurface\AppData\Local\Programs\Python\Python38-32\Python.exe
Python版本:
3.8.2
Python路径:
['C:\\Users\\KentSurface\\Pycharm项目\\学习日志',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32\\Python38.zip',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32',
'C:\\Users\\KentSurface\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site packages']
服务器时间:
2020年3月19日星期四19:40:21+0000
模板呈现期间出错
在模板C:\Users\KentSurface\PycharmProjects\learning\u log\learning\u logs\templates\learning\u logs\base.html中,第0行出现错误
找不到参数为“(“”,)”的“new_entry”的反向项。尝试了1个模式:[“新条目/(?P[0-9]+)/$”]
1.
2.
-
3.
4.
5.
6.
{%block content%}{%endblock%}
7.
在模板的某个地方,您有{%new\u entry some\u var\u name%}
其中some\u var\u name
的值(这不是实际名称,这是我的答案的一个示例)是空字符串('
)。您需要将该变量设置为正在显示的实际条目的id。错误表明主题id
在url
标记中设置不正确。如果您需要更多帮助,请显示new\u entry
视图和template.new\u entry视图.py:def new\u entry(请求,主题\u id):topic=topic.objects.get(id=topic\u id)If request.method!='POST':#未提交任何数据;创建一个空白表单。form=EntryForm()否则:form=EntryForm(data=request.POST)如果form.is_有效():new_entry=form.save(commit=False)new_entry.topic=topic new_entry.save()返回HttpResponseRedirect(反向('learning_logs:topic',args=[topic_id]))context={'topic':topic,'form':form}返回render(请求'learning_logs/new_entry.html',context)new_entry.html:问题是{%new_entry topic_id%}
,应该是{%new entry topic id%}