0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Django】SNS app作成手順03-ログインページの作成

Posted at

—————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">&copy; 2017–2021</p>
  </form>
</main>
{%endblock content%}

—————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'),

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?