2016-06-29 7 views
0

私はdjango-registration-reduxを使用しています。私はnavbarにログインフォームを持っています。私はログイン後も同じページにとどまりたいです。すなわち、ログイン後に私がmypage.com/polls/exampleにいる場合、私はmypage.com/polls/exampleに戻って、設定で設定されたURLには戻りません。 HTML内からログイン後にリダイレクトするdjango-registration-redux

ログインは次のようになります。

{% url "auth_login" as login_url %} 
{% if login_url not in request.get_full_path %} 
    <li> 
     <form class="navbar-form" method="POST" action={{ login_url }}>{% csrf_token %} 
      <input type="text" class="form-control top-bar" name="username" placeholder="email" /> 
      <input type="password" class="form-control top-bar" name="password" placeholder={% trans "password" %} /> 
      <button type="submit" class="btn btn-default">{% trans "Login" %}</button> 
     </form> 
    </li> 
{% endif %} 

はどのように私はそれを行うのですか?

答えて

1

あなたはを使用することができます。

<form class="navbar-form" method="POST" action="{{ login_url }}?next={{request.path}}"> 

これは、現在のページに戻って指すフォームにGETリクエストを追加します。

request.pathについてあなたのsettings.pyにテンプレートコンテキストプロセッサを定義する必要が動作するように

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth", 
    "django.core.context_processors.debug", 
    "django.core.context_processors.i18n", 
    "django.core.context_processors.media", 
    "django.core.context_processors.request", 
) 
関連する問題