В моем приложении возникает следующая ошибка (насколько я обычно видел в Google):
Caught NoReverseMatch while rendering: Reverse for 'add-post' with arguments '()' and keyword arguments '{}' not found.
Дело в том, что я впервые использую обратные URL-адреса, поэтому я немного растерялся, что может быть причиной этой ошибки, и, видимо, у меня все в порядке. Может кто-нибудь сказать мне, что происходит?
файл urls.py
urlpatterns = patterns('e_cidadania.apps.news.views',
url(r'^add/$', 'add_post', name='add-post'),
url(r'^(?P<post_id>\d+)/delete/$', DeletePost.as_view(), name='delete-post'),
url(r'^(?P<post_id>\d+)/edit/$', 'edit_post', name='edit-post'),
url(r'^(?P<post_id>\d+)', ViewPost.as_view(), name='view-post')
)
Template
[...]
{% if perms.news.add_post %}
<div id="tools">
<a href="{% url add-post %}">
<img src="{{ STATIC_URL }}/assets/icons/add16.png" alt="{% trans 'Add new post' %}" title="{% trans 'Add new post' %}"/>
</a>
[...]
News views.py (поле длиной 140 строк, поэтому я его обрезал)
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required, permission_required
# Generic class-based views
from django.views.generic.base import TemplateView, RedirectView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.detail import DetailView
from django.template import RequestContext
from django.views.generic.create_update import create_object
from django.views.generic.create_update import update_object
from django.contrib.auth.models import User
from e_cidadania.apps.spaces.models import Space
from e_cidadania.apps.news.models import Post
from e_cidadania.apps.news.forms import NewsForm
@permission_required('news.add_post')
def add_post(request, space_name):
"""
Create a new post. Only registered users belonging to a concrete group
are allowed to create news. nly site administrators will be able to
post news in the index page.
"""
current_space = get_object_or_404(Space, url=space_name)
form = NewsForm(request.POST or None)
if request.method == 'POST':
form_uncommited = form.save(commit=False)
form_uncommited.author = request.user
# Get space id
place = Space.objects.get(url=space_name)
form_uncommited.space = place
# This should not be necessay since the editor filters the
# script tags
#if "<script>" in form_uncommited.post_message:
# return "SCRIPT TAGS ARE NOT ALLOWED"
if form.is_valid():
form_uncommited.save()
return redirect('/spaces/' + space_name)
return render_to_response('news/post_add.html',
{'form': form, 'get_place': current_space},
context_instance = RequestContext(request))