user = auth.authenticate(username=username,password=password)
if user is not None:
auth.login(request, user)
return redirect('/')
else:
messages.info(request,'invalid credentials')
return redirect('Login')
else:
return render(request,'login.html')
login.html:
============
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Login</title>
</head>
<body>
<form action="Login" action="POST">
{% csrf_token %}
<input type="text" name="username" placeholder="USERNAME"><br>
<input type="password" name="password" placeholder="PASSWORD"><br>
<input typev="submit">
</form>
</body>
<div>
{% for message in messages %}
<h4>{{message}}</h4>
{% endfor %}
</div>
</html>
home.html:
===============
{% if request.user.is_authenticated %}
<li>Hello,{{user.first_name}}</li>
<li><a href="accounts/Logout">Logout</a></li>
{%else%}
<li><a href="accounts/register">Register</a></li>
<li><a href="accounts/Login">Login</a></li>
{%endif%}
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c2984d46-acfb-49a5-a93a-062797e98a23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7EoAZPeeRZnXGsPryNQnv-iqe7nH6YLVFMNHsgiZDixP0qSA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMM5N91jxrsoKsRWjYeWBJWJMR2V_%3DP6kJ3DdS8O%3DHJXXM5xtg%40mail.gmail.com.