I am trying to build my own custom login page for wagtail admin login page. Everything is working fine I removed all the content by extending
{% extends "wagtailadmin/login.html" %}
Login is working but the default sign in button is still showing in my custom login page. How to remove it.
Here my own custom login page code is
{% extends "wagtailadmin/login.html" %}
{% load staticfiles i18n %}
{% block css %}
#Loaded my css files here
{% endblock %}
{% block branding_login %}{% endblock %} # to Remove branding login(login to wagtail site)
{% block fields %}
#Login form here
{% endblock %}
To replace the submit button, define a submit_buttons block on your template.
http://docs.wagtail.io/en/v2.1.1/advanced_topics/customisation/admin_templates.html#submit-buttons
Related
Using Django Abstract Base User model, How do I make the Profile tab show when a user is logged in. Should I create a model/form for Profile, This is the image of the html file. The backend for signup and login works perfectly fine but when a user signs up or logs in, the nav bar doesn't change at all. Please help
{% extends 'base.html' %}
{% block title %}Profile{% endblock %}
{% block content %}
<h1>Hello World</h1>
{% if user.is_authenticated %}
Profile
Logout
{% else %}
Sign Up
Log In
{% endif %}
{% endblock %}
In my Django App settings I've mentioned the following 2 lines in settings.py, it works fine for the normal user but is not good enough for the Admin.
LOGIN_REDIRECT_URL = '/my_app/profile/'
LOGOUT_REDIRECT_URL = '/my_app/login'
When I log out from the Admin, it takes me to the login page of the user, as mentioned in the above LOGOUT_REDIRECT_URL. What I want is that admin logout redirect should go to the Admin login page, not the user login page.
snippet from urls.py
path('admin/', admin.site.urls),
Can anyone suggest the best way to deal with this issue?
EDIT:
I tried to extend Django's Admin base.html which contains the Logout part.
{% block userlinks %}
{% if site_url %}
{% trans 'View site' %} /
{% endif %}
{% if user.is_active and user.is_staff %}
{% url 'django-admindocs-docroot' as docsroot %}
{% if docsroot %}
{% trans 'Documentation' %} /
{% endif %}
{% endif %}
{% if user.has_usable_password %}
{% trans 'Change password' %} /
{% endif %}
{% trans 'Log out' %}
{% endblock %}
How can I change this admin:logout functionality so that it redirects to admin login page?
On my html, I can check if the user is logged in by using the following syntax:
{% if user.is_authenticated %}
<div id="display_something">...</div>
{% else %}
<p>Please Log in</p>
{% endif %}
But what should I do if I want to check if the user is authenticated for every html file I am rendering? Do I have to copy and paste that {% if ... %} block for every single html file? What is the Django's way of handling this issue? What's the good practice?
in your base.html, add your check
{% if user.is_authenticated %}
{% block page %}
{% endblock %}
{% else %}
<p>Please Log in</p>
{% endif %}
then with all your other pages, add {% extends 'base.html' %} at the top. You will need to give it a relative link to base.html.
Then the rest of your code on that page needs to sit between tags like below.
{% block page %}
<!-- all your html code here -->
{% endblock %}
Notice that after block, you need to have the same name. for this example, it is page but you can pick your own variable name.
You shouldn't handle the authentication logic in the template (for the entire site), instead you can use the login_required decorator on your views.
from django.contrib.auth.decorators import login_required
#login_required
def my_view(request):
...
I would like to know how could I add some logic on my admin dashboard. I need to make queries on three different models and show data on Dashboard template but still can't handle the template extention with different models data.
Thanks!
Accomplishing what I was planning to do looked weird. I would need to change the base_site.html rendering view to show up these information, or something else that I don't know how to deal with, so, what i did was:
Extend admin/base.html on /templates/admin loading original data, and overriding some blocks
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}
{{ title }}
{% endblock %}
{% block branding %}
<h1 id="site-name">Administration</h1>
{% endblock %}
{% block nav-global %}
<center>
<button>Reports</button>
<button>Graphs</button>
</center>
{% endblock %}
It's working fine by now, but still don't know how to deal with admin view of base_index.html
in my server I have a lot of apps installed like, facebook_connect, userena, guardian and so on...
For example, I realized that if I customize the:
django-userena / userena / templates / userena / emails / activation_email_message.txt
{% load i18n %}{% autoescape off %}{% load url from future %}
{% if not without_usernames %}{% blocktrans with user.username as username %}Dear {{ username }},{% endblocktrans %}
{% endif %}
{% blocktrans with site.name as site %}Thank you for signing up at {{ site }}.{% endblocktrans %}
{% trans "To activate your account you should click on the link below:" %}
{{ protocol }}://{{ site.domain }}{% url 'userena_activate' activation_key %}
{% trans "Thanks for using our site!" %}
{% trans "Sincerely" %},
{{ site.name }}
{% endautoescape %}
For specified website, and I have more than 4 in the same server, I will make a complete mess in my django_site.
My question is:
How to customize the templates or models in some installed apps without completely change the original django_site?
Thanks in advance,
You cannot change the models, but you can override templates.
In the same directory as manage.py, you would have a directory called templates, there, you can create the following folder hierarchy, and put your custom template.
templates/userena/emails/activation_email_message.txt