2016-06-29 7 views
0

django-registration-redux를 사용하고 있으며 내 탐색 바에 로그인 양식이 있습니다. 로그인 후 같은 페이지에 머물고 싶습니다. 즉. 내가 로그인 한 후 mypage.com/polls/example에있는 경우 설정에 설정된 url이 아닌 mypage.com/polls/example에 다시 있어야합니다. 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", 
)