他のすべての逆URL(編集、削除、その他)は、私のテンプレート、モデルなどでは機能しているようですが、私のビジネスアプリviews.pyでは機能していません(エラーが発生した場合はジャンプしてください)。
from django.views.generic import ListView, DetailView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
from django.core.urlresolvers import reverse
from business.models import Country
{...}
# Delete
class CountryDeleteView(DeleteView):
model = Country
template_name_suffix = '_delete_form'
success_url = reverse('country_listview') # commenting this out makes everything work
プロジェクトurls.py:
from django.conf.urls import patterns, include, url
urlpatterns += patterns('',
url(r'^business/', include('business.urls')),
)
ビジネスアプリurls.py:
from django.conf.urls import patterns, url
from business.views import CountryListView, CountryDetailView
from business.views import CountryCreateView, CountryUpdateView, CountryDeleteView
urlpatterns = patterns('',
url(r'^country/$', CountryListView.as_view(), name='country_listview'),
url(r'^country/(?P<pk>\d+)/$', CountryDetailView.as_view(), name='country_detailview'),
url(r'^country/create/$', CountryCreateView.as_view(), name='country_createview'),
url(r'^country/(?P<pk>\d+)/update/$', CountryUpdateView.as_view(), name='country_updateview'),
url(r'^country/(?P<pk>\d+)/delete/$', CountryDeleteView.as_view(), name='country_deleteview'),
)
汎用編集ビューがデフォルトでコンテキストを既に渡しているという理由model_listview
だけでなく(サブクラスでコンテキスト変数の名前を指定していない)、テンプレートcountry_list.htmlのこのコードと衝突したために使用します。model_list
ListView
model_list
ListView
<ul>
{% for c in country_list %}
<li>{{ c.name }}<br>
<a href="{% url country_detailview c.pk %}">Detalii</a>
<a href="{% url country_updateview c.pk %}">Modifica</a>
<a href="{% url country_deleteview c.pk %}">Sterge</a>
</li>
{% endfor %}
</ul>
そしてエラー:
/ business /country/のNoReverseMatch
引数'()'およびキーワード引数'{}'が見つからない'country_listview'の逆。
リクエスト方法:GET
リクエストURL:_removed_ip_:8000 / business / country /
Djangoバージョン:1.4.3
例外タイプ:NoReverseMatch
例外値:
引数'()'およびキーワード引数'{}'が見つからない'country_listview'の逆。
例外の場所:_reverse_with_prefixの396行目の/usr/lib/python2.7/site-packages/django/core/urlresolvers.py
Python実行可能ファイル:/ usr / bin / python
Pythonバージョン:2.7.3