我收到错误NoReverseMatch at /
。我需要了解导致此问题的原因以及如何解决此问题。
Reverse for 'sites' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
这是我在Mezzanine的设置:
PROJECT_NAME /应用/模板/ index.html中:
<li class="dropdown">
<a href="{% url "sites" %}">{% trans "Sites" %} <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="{% url "sites" %}">{% trans "All Sites" %}</a></li>
<li><a href="{% url "sites_new" %}">{% trans "New Sites" %}</a></li>
<li><a href="{% url "latest_entries" %}">{% trans "Latest Entries" %}</a></li>
</ul>
</li>
PROJECT_NAME /应用/ views.py:
def sites(request):
return render(request, 'lists/sites.html')
def sites_new(request):
return render(request, 'lists/sites_new.html')
def latest_entries(request):
latest_entries = BlogPost.objects.all().filter(site_id=1, publish_date__lte=datetime.date.today())[:50]
context = {'latest_posts': latest_posts}
return render(request, 'lists/latest_entries.html', context)
PROJECT_NAME /应用/ urls.py:
urlpatterns = [
url(r'^sites/$', views.sites, name='sites'),
url(r'^sites/new/$', views.sites_new, name='sites_new'),
url(r'^latest/$', views.latest_entries, name='latest_entries'),
]
PROJECT_NAME / urls.py:
urlpatterns += [
url('^$', direct_to_template, {'template': 'index.html'}, name='home'),
url('^', include('mezzanine.urls')),
]