Python Django-NoReverseMatch位于/。。。。反转为。。。带参数(“52”)
查看了很多类似的NoReverseMatch错误,但无法解决我的问题。这是在Django 我不断得到: NoReverseMatch at/equipment32 找不到参数为“(“”,32)”的“设备”的反面。尝试了1个模式:[“设备(?P[0-9]+)$”] 以下是回溯:Python Django-NoReverseMatch位于/。。。。反转为。。。带参数(“52”),python,django,django-views,django-templates,url-routing,Python,Django,Django Views,Django Templates,Url Routing,查看了很多类似的NoReverseMatch错误,但无法解决我的问题。这是在Django 我不断得到: NoReverseMatch at/equipment32 找不到参数为“(“”,32)”的“设备”的反面。尝试了1个模式:[“设备(?P[0-9]+)$”] 以下是回溯: Traceback (most recent call last): File "C:\ProgramData\Miniconda3\lib\site-packages\django\core\handler
Traceback (most recent call last):
File "C:\ProgramData\Miniconda3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Albert\Desktop\HARVARD CS50\tracker_django\tracker\views.py", line 128, in equipment
return render(request, "jobs/equipment.html", context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\shortcuts.py", line 19, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\template\defaulttags.py", line 443, in render
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
File "C:\ProgramData\Miniconda3\lib\site-packages\django\urls\base.py", line 87, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "C:\ProgramData\Miniconda3\lib\site-packages\django\urls\resolvers.py", line 677, in _reverse_with_prefix
raise NoReverseMatch(msg)
这是我的模板job.html,它生成链接:
<table style="width: 900px">
<caption style="font-size: 25px">Equipment in Scope</caption>
<a href="#equipment_form" style="font-size: 20px">Add Equipment</a>
<tr>
<th>Site ID</th>
<th>Equipment Type</th>
<th>Manufacturer</th>
<th>Model</th>
<th>Test Sheet</th>
</tr>
{% for equipment in equipments %}
<tr>
{% csrf_token %}
<td><a href="{% url 'equipment' equipment.id %}">{{equipment.site_id}}</a></td>
<td>{{equipment.template.classification}}</td>
<td>{{equipment.manufacturer}}</td>
<td>{{equipment.model}}</td>
<td><a href="www.drive.google.com">Test Sheet</td>
</tr>
{% empty %}
<li>No Equipment</li>
{% endfor %}
</table> <br>
这将生成my actual equipment.html:
{% extends "jobs/base.html"%}
{% block title %}
{{equipment.site_id}}
{% endblock %}
{% block body %}
<h1 style = "text-align: center">{{equipment.site_id}} ({{equipment.template.classification}})</h1>
<style>table, th, td {
border: 1px solid black;
border-collapse: collapse;
}</style>
<table style="width:900px">
<caption style="font-size: 25px">Equipment Properties</caption>
<tr>
<td>Equipment Type</td>
<td><b>{{equipment.template.classification}}</b></td>
</tr>
<tr>
<td>Job Site ID or Name</td>
<td><b>{{equipment.site_id}}</b></td>
</tr>
<tr>
<td>Manufacturer</td>
<td><b>{{equipment.manufacturer}}</b></td>
</tr>
<tr>
<td>Model</td>
<td><b>{{equipment.model}}</b></td>
</tr>
<tr>
<td>Link to Manual</td>
<td><a href="https://www.eaton.com"><b>{{equipment.manual}}</b></a></td>
</tr>
<tr>
<td>Link to Item Folder</td>
<td><a><b>{{equipment.template.cloud_link}}</b></a></td>
</tr>
<tr>
<td>Equipment Questions</td>
<td><a><b>{{equipment.template.equipment_questions}}</b></a></td>
</tr>
<tr>
<td>Answers</td>
<!-- <form action="{% url 'equipment' job.id equipment.id%}" method="post">
<td><a><b><textarea id="scope" name="scope" rows="4" cols="55" >{{ equipment.equipment_answers }}</textarea><input type="submit" value="Confirm Answers">
<input type="reset"></b></a></td>
</form> -->
</tr>
<tr>
<td>Scope for This Equipment</td>
<td><a><b>{{equipment.scope}}</b></a></td>
</tr>
<tr>
<td>Additional Notes</td>
<td><a><b>{{equipment.notes}}</b></a></td>
</tr>
</table><br>
<h3>Recommended Test Equpiment</h3>
<ul>
{% for test_equipment in test_equipments %}
<li>
{% csrf_token %}
{{ test_equipment }}
</li>
{% empty %}
<li>No Equipment</li>
{% endfor %}
</ul>
<button onclick="goBack()">Back to Job Page</button>
<script>
function goBack() {
window.history.back();
}
</script>
{% endblock %}
{%extends“jobs/base.html”%}
{%block title%}
{{设备.站点{u id}
{%endblock%}
{%block body%}
{{equipment.site_id}({{equipment.template.classification})
表,th,td{
边框:1px纯黑;
边界塌陷:塌陷;
}
设备性能
设备类型
{{设备.模板.分类}
作业站点ID或名称
{{设备.站点{u id}
制造商
{{设备.制造商}
模型
{{设备.模型}
链接到手册
链接到项目文件夹
{{设备.模板.云链接}
设备问题
{{设备.模板.设备}
答案
本设备的适用范围
{{设备.范围}
附加说明
{{设备.注释}
推荐试验设备
{测试设备%中的测试设备%}
-
{%csrf_令牌%}
{{测试设备}
{%empty%}
- 没有设备
{%endfor%}
返回作业页面
函数goBack(){
window.history.back();
}
{%endblock%}
我不明白为什么它看起来需要两个参数设备(“,35),因为视图函数只接受设备id。非常感谢您的帮助 在模板
equipment.html
中提供了两个参数,只需删除job.id
。虽然有注释,但应该是正确的urlpattern
<form action="{% url 'equipment' equipment.id%}" method="post">
<td><a><b><textarea id="scope" name="scope" rows="4" cols="55" >{{ equipment.equipment_answers }}</textarea><input type="submit" value="Confirm Answers">
<input type="reset"></b></a></td>
</form>
{{equipment.equipment_answers}
我的问题在equipment.html代码的注释部分。我有一个被注释掉的部分,包括:
<form action="{% url 'equipment' equipment.id job.id method="post" %}>....
哇!我删除了我之前注释掉的表单,它可以正常工作。为什么注释掉的html会抛出错误。有点烦人,但非常感谢。无论url标签是否有注释,我都会对它进行处理。谢谢,请投票。你们也可以验证答案。很高兴知道。谢谢我投了更高的票,但我没有“15”的声誉,所以它没有出现。刚刚在这里开了一个账户
<form action="{% url 'equipment' equipment.id%}" method="post">
<td><a><b><textarea id="scope" name="scope" rows="4" cols="55" >{{ equipment.equipment_answers }}</textarea><input type="submit" value="Confirm Answers">
<input type="reset"></b></a></td>
</form>
<form action="{% url 'equipment' equipment.id job.id method="post" %}>....