django.contrib.auth を使用すると、次のようにフォーム コードをベース テンプレートに入れることができます。
<form method="post" action="{% url auth_login %}">
{% csrf_token %}
<p><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="30" /></p>
<p><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></p>
<input type="submit" value="Log in" />
<input type="hidden" name="next" value="" />
</form>
あなたがする必要があるのは、代わりに次の値を変更することです:
<input type="hidden" name="next" value="" />
次のようになります。
<input type="hidden" name="next" value="{{ request.get_full_path }}" />
リクエストオブジェクトにアクセスするには、必ず含めてください
'django.core.context_processors.request'
テンプレート コンテキスト プロセッサで。この方法では、Django 組み込みビューを使用しているため、ログイン用のコンテキスト プロセッサを作成する必要はありません。