I'm a beginner to django. I've created a basic user registration and login application.
For some reason it doesn't redirect from the login page.
Here is the views.py file:
`
def login_view(request):
form = LoginForm()
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
username = request.POST.get("username")
password = request.POST.get("password")
user = authenticate(request, username=username, password=password)
# print(user)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect("mysite\polls\templates\polls\profile.html")
context = {"loginform": form}
return render(request, "polls/login.html", context=context)
Here is the urls.py file:
from django.urls import path
from . import views
urlpatterns = [
path("", views.homepage, name=""),
path("register", views.register, name="register"),
path("login", views.login_view, name="login"),
path("profile", views.profile, name="profile"),
path("logout", views.logout, name="logout"),
]
here is the login.html page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Welcome to the Login Page</h1>
<form method="POST" autocomplete="off">
{% csrf_token %}
{{ loginform.as_p }}
<input type="submit" value="Login">
</form>
</body>
</html>
`
I've tried adding event listeners to redirect but that too doesn't work.
This is the repo: https://github.com/shasank01/user-auth