gpt4 book ai didi

python - Django:渲染时捕获 NoReverseMatch:使用参数 '*' 和关键字参数 '()' 未找到 '{}' 的反向

转载 作者:太空狗 更新时间:2023-10-30 00:46:38 26 4
gpt4 key购买 nike

错误:

Caught NoReverseMatch while rendering: Reverse for 'archive' with arguments '()' and keyword arguments '{}' not found.

Template error

In template /home/bravedick/Aptana Studio 3 Workspace/blog/templates/homepage/index.html, error at line 7

第 7 行:

6   <a href="{% url index %}">Index</a>
7 <a href="{% url archive %}">Archive</a>
8 <a href="{% url contacts %}">Contacts</a>

主要 urls.py:

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
(r'^$', include('blog.apps.homepage.urls')),
# url(r'^$', 'blog.views.home', name='home'),
# url(r'^blog/', include('blog.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)

我的 urls.py:

from django.conf.urls.defaults import *

urlpatterns = patterns('blog.apps.homepage.views',
url(r'^$', 'index', name='index'),
url(r'^about/$', 'about', name='about'),
url(r'^archive/$', 'archive', name='archive'),
url(r'^contacts/$', 'contacts', name='contacts'),
)

观看次数:

from django.shortcuts import render_to_response
from blog.apps.data.models import Entry

def index(request):
entries = Entry.objects.published_entries().order_by('-id')
ctx = {'entries':entries}
return render_to_response("homepage/index.html", ctx)

def about(request):
return render_to_response("homepage/about.html")

def contacts(request):
return render_to_response("homepage/contacts.html")

def archive(request):
return render_to_response("homepage/archive.html")

最佳答案

我发现您的主要网址配置存在一个直接问题。您有一个“$”符号,表示您的 include 语句中 url 的结尾。

那一行应该是:

(r'^', include('blog.apps.homepage.urls')),

这是 the documentation for include .

还要检查 blog.apps.homepage.urls 是否是有效的导入路径。运行以下命令打开 Django shell:

./manage.py shell

然后输入:

from blog.apps.homepage import urls

如果您遇到导入错误,请尝试找出正确的导入路径并在您的 include 语句中使用它。

关于python - Django:渲染时捕获 NoReverseMatch:使用参数 '*' 和关键字参数 '()' 未找到 '{}' 的反向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6635051/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com