I created a combined registration and login form that is linked to the LoginView, but I ran into a problem relating the fields in the form to the LoginView mechanism (it does not use them). Can anyone suggest if it's possible to use custom template styling instead of using the standard approach with unstyled {{form.username}}, {{form.password} } and the like? Thanx!
Here is my template login.html
<div class="form-structor">
<div class="signup slide-up">
<h2 class="form-title" id="signup"><span>or</span>SignUp</h2>
<form method="post">
{% csrf_token %}
<div class="form-holder">
<label>
<input id="uname" type="text" class="input" placeholder="Name" required autocomplete="off"/>
</label>
<label>
<input id="pwd" type="password" class="input" placeholder="Password" required autocomplete="off"/>
</label>
<label>
<input id="pwd2" type="password" class="input" placeholder="Retype password" required autocomplete="off"/>
</label>
</div>
<button id="id_signup" class="submit-btn">SignUp</button>
</form>
</div>
<div class="login">
<div class="center">
<h2 class="form-title" id="login"><span>or</span>Login</h2>
<form method="post">
{% csrf_token %}
<div class="form-holder">
<label>
<input name="{{ form.name.name }}" id="id_name" type="text" class="input" placeholder="Name" required autocomplete="off"/>
</label>
<label>
<input name="{{ form.name.name }}" id="id_password" type="password" class="input" placeholder="Password" required autocomplete="off"/>
</label>
</div>
<button id="id_login" class="submit-btn">Login</button>
</form>
</div>
</div>
</div>
And simple use:
class SimpleLoginUser(LoginView):
template_name = 'login/login.html'
def get_success_url(self):
return '/show-person-visits/'+str(self.request.user.person.id)+'/'
Does anyone have experience with this?
You can have bootstrap css based style with less codes with django-package called django-crispy-forms. to install
crispyformsyou can learn how to use it from Vitor Freitas blog
an updated version bootstrap 5 is also supported now to accommodate that you need to install
crispy-bootstrap5along with django-crispy-forms. To install