—————login.html作成----------
{% extends 'base.html' %}
{%block content%}
{{context}}<main class="form-signin">
<form method='POST'>{% csrf_token %}
<h1 class="h3 mb-3 fw-normal">Please login</h1>
<div class="form-floating">
<input type="text" class="form-control" id="floatingInput" name='username' placeholder="name@example.com">
<label for="floatingInput">username</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" name='password' placeholder="Password">
<label for="floatingPassword">Password</label>
</div>
<button class="w-100 btn btn-lg btn-primary" type="submit">login</button>
<p class="mt-5 mb-3 text-muted">© 2017–2021</p>
</form>
</main>
—————views.pyへ追記----------
def loginfanc(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(request,username = username,password = password)
if user is not None:
login(request,user)
return render(request,'login.html',{'context':'login'})
else:
return render(request,'login.html',{'context':'notlogin'})
return render(request,'login.html',{'context':'get method’})
—————urls.pyへ追記----------
path('login/', loginfanc, name = 'login'),