简体   繁体   中英

Django Authentication Form not authenticating and redirecting

After I put the correct password, it should redirect to "/articles" , BUT IT'S REFRESHING THE LOGIN PAGE ONLY.

def login(request):

    if request.method == 'POST':
        form = a_form(data=request.POST)
        if form.is_valid():
            return redirect('/articles')
    else:
        form = a_form()
        context = {'form': form}
    return render(request, 'accounts/login.html', context)

This is what my html looks like: {% extends 'articles/base.html' %}

{% block content %}
<div class="container">
    <form class="login" action="{%url 'login'%}">
        {%csrf_token%}
        {{form}}
        <input type="submit" value="login">
    </form>
</div>
{% endblock %}

I wonder what is that I'm missing here.

I missed out the method='post' in my html file. Fixed it! :

<form class="login" action="{%url 'login'%}" method="POST">
    {%csrf_token%}
    {{form}}
    <input type="submit" value="login">
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM