()<--This in screenshot of error i'm getting this is the code of both html page and python function
<!DOCTYPE html>
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1> Signin</h1>
<form action="/signin" method="post">
{% csrf_token %}
<label for="">Username</label>
<input type="text" id="username" name="username" placeholder="Enter your Username" required>
<br>
<label for="">Password</label>
<input type="password" id="pass1" name="pass1" placeholder="Enter your Password" required>
<br>
<button type="submit">Sign in</button>
</form>
</body>
</html>
def signin(request):
if request.method == "POST":
username = request.POST["username"]
pass1 = request.POST["pass1"]
user = authenticate(username=username, password=pass1)
if user is not None:
login(request, user)
fname = user.first_name
return render(request, "authentication/index.html", {fname: "fame"})
else:
messages.error(request, "Wrong Credentials")
return redirect("home")
return render(request, "authentication/signin.html")
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path("", views.home, name="home"),
path("signup/", views.signup, name="signup"),
path("signin/", views.signin, name="signin"),
path("signout/", views.signout, name="signout"),
]
我认为这在您的错误中得到了很好的解释。您需要在表单操作中附加斜线:
<form action="/signin/" method="post">
或者,由于您在发布表单的同一 URL 上呈现表单,您可以简单地省略操作(这样更容易重用):
<form action="" method="post">