django中的django NoReverseMatch异常 [英] django NoReverseMatch Exception in django
本文介绍了django中的django NoReverseMatch异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试了本网站中的许多解决方案来解决该问题,但仍然出现错误.在这里,我放置了所有必需的信息:
I have tried many of the solutions in this website to solve the issue but I still get the error. Here I put all the needed information:
views.py:
def about(request):
return render_to_response('homepage/about.html')
urls.py:
urlpatterns = patterns('blog.apps.homepage.views',
url(r'^$', 'index', name="homepage_index"),
url(r'^about/$', 'about', name="homepage_about"),
url(r'^contact/$', 'contact', name="homepage_contact"),
url(r'^archive/$', 'archive', name="homepage_archive"),
)
全局urls.py:
(r'^$',include('blog.apps.homepage.urls')),
全局设置.py:
ROOT_URLCONF = 'blog.urls'
树:
templates/
├── base.html
└── homepage
├── about.html
├── archive.html
├── contact.html
└── index.html
index.html:
index.html:
{% extends "base.html" %}
{% load url from future %}
{% block title %}
Index Page
{% endblock %}
{% block navi %}
<a href="{% url 'homepage_index' %}">home</a> -
<a href="{% url 'homepage_about' %}">about</a> -
<a href="{% url 'homepage_contact' %}">contact</a> -
<a href="{% url 'homepage_archive' %}">archive</a>
{% endblock %}
{% block content %}
<h3>Entries:</h3>
{%for e in entries %}
<div>{{e.title}} - {{e.created}}</div>
<div>{{e.text}}</div>
<br/>
{% endfor %}
{% endblock %}
{%block footer %}
2012 - MyBlog
{% endblock %}
错误:
使用参数'()'和关键字参数对'homepage_about'进行反向找不到"{}".
Reverse for 'homepage_about' with arguments '()' and keyword arguments '{}' not found.
推荐答案
尝试更改
(r'^$', include('blog.apps.homepage.urls'))
到
(r'', include('blog.apps.homepage.urls'))
原因是 $
符号(用于匹配字符串的结尾),这意味着之后不应再出现任何内容.但是,由于要包含网址,因此 $
不应该存在.
The reason is $
sign (used to match end of string) which means that there should not come anything afterwards. But as you are including the urls then $
should not be there.
这篇关于django中的django NoReverseMatch异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文