[Answer]-Login_required โ€“ login success not redirecting to "next"

1๐Ÿ‘

โœ…

if you are using django.contrib.auth.login() that should mean you have simply to override django default login by using LOGIN_REDIRECT_URL for example, you only have to override the views.py if you want to sign up and redirect to login.
so you can override django login urls.py login.html and other.

 settings.py:
 LOGIN_REDIRECT_URL='/' # to redirect to the home after login

urls.py:
urlpatterns += patterns('django.contrib.auth.views',
    (r'^login/$','login',{'template_name':'registration/login.html'},'login'),
)

login.html :
<div id="main">
{% if form.errors %}
     <ul class="errorlist">
     <li>You entered an invalid username or password</li>
    </ul>       <br/>
      {% endif %}
      <form method="POST" action="{% url "django.contrib.auth.views.login" %}">{% csrf_token %}
        <table summary="login" id="login">
        <caption>Login</caption>
        <tr>
                <td>{{form.username.label_tag}}:</td>
                <td>{{form.username}}</td>          
        </tr>

        <tr>
                <td>{{form.password.label_tag}}:</td>
                <td>{{form.password}}</td>          
        </tr>           
        <tr>
        <td colspan="2" class="right">
    <input type="submit" value="Login" /></td>          
        </tr>
        </table>
        <input type="hidden" name="next" value="{{next}}" />
        </form>

    </div>
๐Ÿ‘คdrabo2005

Leave a comment