2016-07-06 19 views
0

私はDjangoを使い始めました。単純なアプリにユーザー認証を追加しようとしています。私はDjango 1.9で作業しています。これをできるだけ簡単に実行しようとしています。ログインとログアウトは動作しますが、「パスワードの変更」ではpassword_change_doneのNoReverseMatchエラーが発生します。 /league/templates/league/index.htmlでdjango password_change noreversematch

app_name = 'league' 
urlpatterns = [ 
    url(r'^$', views.index, name='index'), 
    url('^', include('django.contrib.auth.urls')), 
] 

私urls.pyから

、私が持っている:

<a href="{% url 'league:login' %}">Login</a> 
<a href="{% url 'league:logout' %}">Logout</a> 
<a href="{% url 'league:password_change' %}">Change Password</a> 
<a href="{% url 'league:password_change_done' %}">Change Password Done</a> 

は、私はこれらのファイルを作成/リーグ/テンプレート/登録/ 。 password_change_form.htmlとpassword_change_done.htmlは現在何もしていません。表示されるのは文字列だけです。私は、 "パスワードの変更" リンクをクリックすると

  • login.htmlと
  • logged_out.html
  • password_change_form.html
  • password_change_done.html

、私が取得:

NoReverseMatch at /league/password_change/ 
Reverse for 'password_change_done' with arguments'()' and keyword arguments '{}' not found. 

"パスワードの変更完了"リンクがsilです私はそれを加えて何が起こるか見てみましょう。それはうまく動作します。私がクリックすると、password_change_done.htmlが期待通りに表示されます。私はstackoverflowの上で似たようなケースを発見した

Environment: 


Request Method: GET 
Request URL: http://localhost:8000/league/password_change/ 

Django Version: 1.9.2 
Python Version: 3.4.3 
Installed Applications: 
['league.apps.LeagueConfig', 
'django.contrib.admin', 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.staticfiles'] 
Installed Middleware: 
['django.middleware.security.SecurityMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.middleware.clickjacking.XFrameOptionsMiddleware'] 



Traceback: 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response 
    149.      response = self.process_exception_by_middleware(e, request) 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response 
    147.      response = wrapped_callback(request, *callback_args, **callback_kwargs) 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper 
    76.    return view(request, *args, **kwargs) 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/utils/decorators.py" in _wrapped_view 
    149.      response = view_func(request, *args, **kwargs) 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 
    23.     return view_func(request, *args, **kwargs) 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/contrib/auth/views.py" in inner 
    49.   return func(*args, **kwargs) 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/contrib/auth/views.py" in password_change 
    308.   post_change_redirect = reverse('password_change_done') 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/core/urlresolvers.py" in reverse 
    600.  return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))) 

File "/home/mriley/.virtualenvs/django1_8/lib/python3.4/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix 
    508.        (lookup_view_s, args, kwargs, len(patterns), patterns)) 

Exception Type: NoReverseMatch at /league/password_change/ 
Exception Value: Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 

、私はこれに私のurls.pyを変えthis one.

含む:

ここで私は、「パスワードの変更」リンクをクリックしたときからのスタックトレースです

url(r'^password_change/$', 
    auth_views.password_change, 
    {'current_app': 'league'}, 
    name='password_change'), 
url(r'^password_change_done/$', 
    auth_views.password_change_done, 
    {'current_app': 'league'}, 
    name='password_change_done'), 

でも違いはありませんが、NoReverseMatchエラーが表示されます。

私は「パスワードを変更する」と間違って何をしているのですか?

おかげで、 マイク

答えて

0

password_changeビューdoes not useリダイレクトURLを決定するcurrent_appパラメータ。

url(r'^password_change/$', 
    auth_views.password_change, 
    {'post_change_redirect': 'league:password_change_done'}, 
    name='password_change'), 

current_appパラメータはテンプレートだけで{% url %}タグで使用されているが、それはdeprecatedあるとDjango 2.0で削除されます:あなたは、明示的に名前空間を含むビュー名を渡す必要があります。テンプレートコンテキストで現在のアプリケーションが必要な場合は、request.current_appと設定する必要があります。

+0

私は、感謝しました!私はpassword_change_doneのURL宣言を追加し、それは完全に機能しました。 – Mike