Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LoginForm(forms.Form):
- username = forms.CharField(label = "Username")
- password = forms.CharField(label = "Password", widget=forms.PasswordInput)
- def loginUser(request):
- form = LoginForm(request.POST or None)
- context = {
- "form": form
- }
- if form.is_valid():
- username = form.cleaned_data.get("username")
- password = form.cleaned_data.get("password")
- user = authenticate(username = username, password=password)
- if user is None:
- messages.info(request,"Username or Password is incorrect! Try again.")
- return render(request,"login.html", context)
- messages.success(request,"Login successful! Welcome honey.")
- login(request,user)
- return redirect("index")
- return render(request,"login.html",context)
- app_name = "user"
- urlpatterns = [
- path('register/',views.register, name ="register"),
- path('login/',views.loginUser, name ="login"),
- path('logout/',views.logoutUser, name ="logout"),
- ]
- {% extends "layout.html" %}
- {% block body %}
- {% load crispy_forms_tags %}
- <div class="row">
- <div class="col-md-6 offset-md-3">
- <h3>Login</h3>
- <hr>
- <form method = "post">
- {% csrf_token %}
- {{form|crispy}}
- <button type = "submit" class = "btn btn-danger">Sign In</button>
- </form>
- </div>
- </div>
- {% endblock %}
Add Comment
Please, Sign In to add comment