Python NoReverseMatch at/13/download/in Django
我一直在尝试使用Django开发一个小应用程序。一切正常。然后,我添加了一个“下载”按钮来向用户发送邮件。每当我点击该按钮时,就会出现以下错误:Python NoReverseMatch at/13/download/in Django,python,django,django-templates,django-views,Python,Django,Django Templates,Django Views,我一直在尝试使用Django开发一个小应用程序。一切正常。然后,我添加了一个“下载”按钮来向用户发送邮件。每当我点击该按钮时,就会出现以下错误: NoReverseMatch at /13/download/ Reverse for 'about' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/about/$'] URL.py: from django.conf.urls import
NoReverseMatch at /13/download/
Reverse for 'about' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/about/$']
URL.py:
from django.conf.urls import url,include
from . import views
app_name = 'set_goals'
urlpatterns = [
url(r'^$',views.index,name='index'),
url(r'^(?P<pk>[0-9]+)/about/$',views.about,name='about'),
url(r'^(?P<pk>[0-9]+)/download/$', views.download, name='download'),
]
从django.conf.url导入url,包括
从…起导入视图
应用程序名称='设置目标'
URL模式=[
url(r'^$',views.index,name='index'),
url(r'^(?P[0-9]+)/about/$,views.about,name='about'),
url(r'^(?P[0-9]+)/download/$',views.download,name='download'),
]
模板:
{% extends 'base.html' %}
{% block title %}Immediate{% endblock %}
{% block content %}
<div class="container">
{% if user.is_authenticated %}
<div class="container">
<div class="row">
<div class="col-md-6">
{% if immediate.body %}
<h2>{{immediate.title}}</h2>
<pre>{{immediate.body}}</pre>
{% else %}
<h2>Immediate Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
<div class="col-md-6">
{% if necessary.body %}
<h2>{{ necessary.title }}</h2>
<pre>{{ necessary.body }}</pre>
{% else %}
<h2>Necessary Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-md-6">
{% if longterm.body %}
<h2>{{ longterm.title }}</h2>
<pre>{{ longterm.body }}</pre>
{% else %}
<h2>Longterm Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
<div class="col-md-6">
{% if notnecessary.body %}
<h2>{{ notnecessary.title }}</h2>
<pre>{{ notnecessary.body }}</pre>
{% else %}
<h2>Not Necessary Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
</div>
<div class="row">
<a href="{% url 'set_goals:download' user.id %}" class="btn btn-primary">Download →</a>
</div>
</div>
{% else %}
<h2>Please Login First</h2>
{% endif%}
</div>
{% endblock %}
{%extends'base.html%}
{%block title%}立即的{%endblock%}
{%block content%}
{%if user.u经过身份验证%}
{%if immediate.body%}
{{immediate.title}}
{{immediate.body}}
{%else%}
近期目标
还有待安置
{%endif%}
{%如有必要。正文%}
{{必要的.title}
{{必需的.body}
{%else%}
必要目标
还有待安置
{%endif%}
{%if longterm.body%}
{{longterm.title}
{{longterm.body}}
{%else%}
长期目标
还有待安置
{%endif%}
{%如果没有必要。正文%}
{{notneedly.title}}
{{notneedly.body}}
{%else%}
不必要的目标
还有待安置
{%endif%}
{%else%}
请先登录
{%endif%}
{%endblock%}
下载.html:
{%extends'base.html%}
{%block title%}立即的{%endblock%}
{%block content%}
{%if user.u经过身份验证%}
{%if immediate.body%}
{{immediate.title}}
{{immediate.body}}
{%else%}
近期目标
还有待安置
{%endif%}
{%如有必要。正文%}
{{必要的.title}
{{必需的.body}
{%else%}
必要目标
还有待安置
{%endif%}
{%if longterm.body%}
{{longterm.title}
{{longterm.body}}
{%else%}
长期目标
还有待安置
{%endif%}
{%如果没有必要。正文%}
{{notneedly.title}}
{{notneedly.body}}
{%else%}
不必要的目标
还有待安置
{%endif%}
{%else%}
请先登录
{%endif%}
{%endblock%}
当我点击下载按钮时,我得到了上面的错误。这里出了什么错?如何纠正?我是新手。请帮帮我。提前谢谢
通常,当呈现模板中的模板标记出错时,会发生此错误
django将在呈现之前检查所有模板标记,如果模板标记中存在任何不匹配或错误。它将引发此异常
好的,问题可能与
{%url'about'.
标记有关,该标记在下载.html
中看不到。它可能在base.html
中。查找该模板标记。这是作为答案发布的,但它不会尝试回答问题。它可能是一条注释。
{% extends 'base.html' %}
{% block title %}Immediate{% endblock %}
{% block content %}
<div class="container">
{% if user.is_authenticated %}
<div class="container">
<div class="row">
<div class="col-md-6">
{% if immediate.body %}
<h2>{{immediate.title}}</h2>
<pre>{{immediate.body}}</pre>
{% else %}
<h2>Immediate Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
<div class="col-md-6">
{% if necessary.body %}
<h2>{{ necessary.title }}</h2>
<pre>{{ necessary.body }}</pre>
{% else %}
<h2>Necessary Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-md-6">
{% if longterm.body %}
<h2>{{ longterm.title }}</h2>
<pre>{{ longterm.body }}</pre>
{% else %}
<h2>Longterm Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
<div class="col-md-6">
{% if notnecessary.body %}
<h2>{{ notnecessary.title }}</h2>
<pre>{{ notnecessary.body }}</pre>
{% else %}
<h2>Not Necessary Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
</div>
<div class="row">
<a href="{% url 'set_goals:download' user.id %}" class="btn btn-primary">Download →</a>
</div>
</div>
{% else %}
<h2>Please Login First</h2>
{% endif%}
</div>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Immediate{% endblock %}
{% block content %}
<div class="container">
{% if user.is_authenticated %}
<div class="container">
<div class="row">
<div class="col-md-6">
{% if immediate.body %}
<h2>{{immediate.title}}</h2>
<pre>{{immediate.body}}</pre>
{% else %}
<h2>Immediate Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
<div class="col-md-6">
{% if necessary.body %}
<h2>{{ necessary.title }}</h2>
<pre>{{ necessary.body }}</pre>
{% else %}
<h2>Necessary Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-md-6">
{% if longterm.body %}
<h2>{{ longterm.title }}</h2>
<pre>{{ longterm.body }}</pre>
{% else %}
<h2>Longterm Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
<div class="col-md-6">
{% if notnecessary.body %}
<h2>{{ notnecessary.title }}</h2>
<pre>{{ notnecessary.body }}</pre>
{% else %}
<h2>Not Necessary Goals</h2>
<p>Yet to be placed!</p>
{% endif %}
</div>
</div>
</div>
{% else %}
<h2>Please Login First</h2>
{% endif%}
</div>
{% endblock %}
Reverse for 'something' with arguments '('',)' not found. 1 pattern(s) tried: ['some path']
In download.html there is no about tag may it will be in base.html.check may be it is in correct or update question with base.thml