开发者

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

开发者 https://www.devze.com 2023-03-18 06:21 出处:网络
Error: Caught NoReverseMatch while rendering: Reverse for \'archive\' with arguments \'()\' and keyword arguments \'{}\' not found.

Error:

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

line 7:

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

main 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)),
)

my 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'),
)

views:

f开发者_JAVA技巧rom 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")


I can see one immediate problem with your main url configuration. You have a '$' symbol, signifying end of the url in your include statement.

That line should read:

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

Here's the documentation for include.

Also check that blog.apps.homepage.urls is a valid import path. Run the following to open a django shell:

./manage.py shell

Then type:

from blog.apps.homepage import urls

If you get an import error, try to work out what the proper import path should be and use that in your include statement.

0

精彩评论

暂无评论...
验证码 换一张
取 消