Login Login to Django Sadjcore Utilities to log in to a SmartAdmin for Django application
You are not currently logged in via the Django authentication system, press the button to test login functionality
Login Page: SmartAdmin Integration
The sadjdemo
Django app contains an integrated login screen
sadjcore
to make construction simple. In fact, this page is a perfect demonstration of how easily new pages are pulled together using SmartAdmin for Django as a starting point.
In the raw HTML, the SmartAdmin CSS and theme integration are handled by this line within the head element:
{% include 'sadjcore/fragments/pageheader.html' with title='Login - SmartAdmin for Django' %}
And this line at the top of the body element:
{% include 'sadjcore/fragments/bodyscript.html' with css_only='true' %}
Settings are accessed from local browser storage; the user's settings from the database can't be accessed as the user will not be logged in, and also the intention is not to interfere with the standard Django admin code. Note that the Sadj code allows the colour scheme and skin settings to be picked up separately to the layout: for the login page the layout is fixed and only the colours and skin settings are loaded. This is all handled by simply including the bodyscript.html
template into the page with css_only='true'
.
Login Page: Django Authentication Integration
The hooks into Django's inbuilt auth_views
login are via a standard Django-compatible form, located in sadjcore
:
<form method="post">
{% csrf_token %}
{% include 'sadjcore/forms/non_field_errors.html' %}
<div class="form-group">
<label class="form-label" for="{{ form.username.id_for_label }}">Username</label>
<input type="text" name="username" autofocus autocapitalize="none" autocomplete="username" maxlength="150" required id="id_username" value="" class="form-control form-control-lg" placeholder="your Django username">
<div class="help-block">Your Django app username</div>
</div>
{% include 'sadjcore/forms/field_errors.html' with field=form.username %}
<div class="form-group">
<label class="form-label" for="{{ form.password.id_for_password }}">Password</label>
<input type="password" name="password" class="form-control form-control-lg" autocomplete="password-current" id="id_password" placeholder="your Django password" value="" required>
<div class="help-block">Your password</div>
</div>
{% include 'sadjcore/forms/field_errors.html' with field=form.password %}
{% if request.GET.next %}
<input type="hidden" name="next" value="{{ request.GET.next }}"/>
{% else %}
<input type="hidden" name="next" value="{{ next_page }}"/>
{% endif %}
<div class="row no-gutters">
<div class="col-lg-6 pl-lg-1 my-2">
<button type="submit" class="btn btn-info btn-block btn-lg">Secure login</button>
</div>
</div>
</form>
The autocomplete
attributes will invoke the browser's login-related prompts, i.e. providing a drop-down of past usernames and suggesting randomly-generated secure passwords.
The standard Django login view is configured to pick up the form by an entry in urls.py:
path('login/', auth_views.LoginView.as_view(template_name='sadjdemo/login.html'), name='login')
Once logged in the user's theme settings from the database will be accessed as described at Settings