我已尝试过本网站的许多解决方案来解决问题,但我仍然遇到错误。在这里,我提供了所有需要的信息:
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"),
)
global urls.py:
(r'^$',include('blog.apps.homepage.urls')),
全球settings.py:
ROOT_URLCONF = 'blog.urls'
树:
templates/
├── base.html
└── homepage
├── about.html
├── archive.html
├── contact.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' 找不到“{}”。
答案 0 :(得分:3)
尝试更改
(r'^$', include('blog.apps.homepage.urls'))
到
(r'', include('blog.apps.homepage.urls'))
原因是$
符号(用于匹配字符串的结尾),这意味着事后不应该有任何结果。但是当你包含网址时,$
不应该在那里。