Reputation: 104
I'm working on the django authentification request and I get the forbidden error I checked my code but it doesn't seem I'm having an error.
HTML
<div class="grad"></div>
<div class="header">
<div>MLAT<span>SI</span></div>
</div>
<form action="{{views.login_user}}" method="POST">{% csrf_token %}
<div class="login">
<img src="{% static "img/Airplane.png" %}">
<div id="h" class="home">
<input type="text" placeholder="Login" name="username" value="">
<input type="password" placeholder="Mot de passe" name="password" value="">
<input style="float: left; width: 173px" type="submit" value="Log in" >
<input formaction="/form_registration.html/" style="float: right; width: 173px" type="submit" value="Register">
views.py
def login_user(request):
username = request.POST.get("username")
password = request.POST.get("password")
user = authenticate(username=username, password=password)
if user is not None and user.is_active:
login(request, user)
return HttpResponse("You're logged in.")
else:
return HttpResponse("Your username and password didn't match.")
Upvotes: 0
Views: 1276
Reputation: 83
you seem like you have a problem in the import package. And the way you're calling the views are incorrect you should read the Django documentation well
Upvotes: 2
Reputation: 1537
Looks like a duplicate of: Django - {% csrf_token %} was used in a template, but the context did not provide the value
Basically, your login_user
view isn't making use of any render/context, hence the error (I don't know if that's the same view that is called when the url for login is called). So Django sees the csrf_token but never converts it to an actual token value.
from django.shortcuts import render
But really both your form and view look very wrong. The form action {{ views.login_user }} is incorrect. You can't call a view that way. And your Register button goes to what looks like an HTML page.
Upvotes: 0