Django Admin Login Background - django

how can i change only background image of admin login site in django? i have tried some method but didnt achieved.
i have put base_site.html to under templates\admin.
what is next for coding about background image?
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %}
{% block extrastyle %}
<style type="text/css">
# body {background-color: #444444;}
</style>
{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans 'Admin Login' %}</h1>
{% endblock %}
{% block nav-global %}{% endblock %}

The correct code is:
{% block extrastyle %}
<style type="text/css">
body.login {background-color: #444444;}
</style>
{% endblock %}
The problem was the # in the css which refers to an id, ie <some_tag id="body"> rather than <body>. body.login targets a body tag with a login class, ie <body class="login">, which is what the django admin site uses to identify the body of just the login screen.

Related

Django admin header customisation with my software release

I have in version of my software (settings.release=1.0.14) and I want to show this info in django admin header under or after the product logo, but no idea how to do it.
My base_site.html is:
{% extends "admin/base.html" %}
{% load static %}
{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
{% block branding %}
<h1 id="site-name">
<a href="{% url 'admin:index' %}">
<img src="{% static 'lumbara.png' %}" height="50px" />
</a>
</h1>
{% endblock %}
{% block extrastyle %}
<style>
.module h2, .module caption, .inline-group h2,#header
{
/*margin: 0;*/
/*padding: 2px 2px 2px 2px;*/
/*font-size: 12px;*/
/*text-align: left;*/
/*font-weight: bold;*/
background: #006400 url(../img/default-bg.gif) top left repeat-x;
color: #fff;
}
</style>
{% endblock %}
{% block nav-global %}{% endblock %}
You have to write your own context_processors which returns a dictionary with your release variable. Then add it to the TEMPLATE settings, and you can use this variable in your templates - look at this answer for more info.

Hide Django logo/name in header Django admin tool

I want to hide/change the name displayed in the header bar, the label that I want to change is "DJANGO" word as the next image shows"
Another solution for customizing the admin header.
Just copy /django/contrib/admin/templates/admin/base_site.html from django source (Link Here) and paste it under your templates directory.
For example,
your_project/templates/admin/base_site.html
Now you can change whatever you like in this template.
Hope this helps.
The easiest way is to simply add the following lines to your main urls.py:
admin.site.site_title = 'My Heading'
admin.site.site_header = 'My Heading'
admin.site.index_title = 'My Heading'
See the Django documentation for more attributes.
make a custom template file like:
templates/admin/base_site.html
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}YOUR WEB TITLE{% endblock %}
{% block branding %}
<h1 id="site-name">Your Site Name</h1>
{% endblock %}
{% block extrahead %}
<style type="text/css">
#header #branding h1{
background: None; // here you remove the django image
}
</style>
{% endblock %}
Just Share improve with favicon icon :
{% extends "admin/base.html" %}
**{% load staticfiles %}**
{% block title %}BROKR System{% endblock %}
{% block extrahead %}
**<link rel="shortcut icon" href="{% static 'img/logo1.png' %}"/>**
{% endblock %}
{% block branding %}
<h1 id="site-name">BROKR System</h1>
{% endblock %}
{% block nav-global %}{% endblock %}
You will need to locate your
django/contrib/admin/templates/admin/base.html
This might be located in your
env/lib/site-packages
Thus, you find it in
env/lib/site-packages/django/contrib/admin/templates/admin/base.html
This is if you have virtual environment setup.
Else it will be in your base project folder containing your settings.py, wsgi.py etc
In:
your_base_folder/lib/site-packages/django/contrib/admin/templates/admin/base.html
Then go to line 32-34
<div id="branding">{% block branding %}{% endblock %}</div>
Replace the below with your img or text or h1
{% block branding %}{% endblock %}
For example:
<div id="branding"><img href='example.png'></div>
Or You could use the preferred django's
{{% url (bla.bla bla) %}}

Django template rendering extend tag incorrectly

I have three Django templates:
base.html:
user_links.html
user_detail.html
I want user_links.html to extend base.html. Next, I want user_detail.html to extend user_links.html and base.html.
Here's base.html:
<head>
<title>Cool App</title>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/main.css" />
</head>
<body>
<h1>Cool App</h1>
<div class="navbar">
<p>
HOME |
{% if user.is_authenticated %}
LOGOUT
{% else %}
LOGIN
{% endif %}</p>
{% block content %}
{% endblock %}
{% block pagination %}
{% endblock %}</div>
Here's user_links.html:
{% extends "base.html" %}
Yellow
Pink
Green
{% block content %}
{% endblock %}
And here's user_detail.html
{% extends "user_links.html" %}
{% block content %}
<h2>{{ object.username }}'s Profile</h2>
{% if object.userprofile.bio %}
{{ object.userprofile.bio }}
{% endif %}
{% endblock %}
So when the browser renders user_detail.html, I want it to (i) show the stylesheet and navigation links from base.html, (ii) show the word Yellow, Pink, Green from user_links.html, (iii) and show the user's username and bio. But (ii) is not being rendered at all, though (i) and (iii) are correctly rendering.
How should the templates be set up so that I see (i), (ii) and (iii) in user_detail.html? Please advise.
Note: all three templates reside in the same directory. I'm on Django 1.5
If you extends a base.html template, no content not surrounded by {% block %} will be rendered at all.
You could create additional {% block precontnet %}{% endblock %} in base.html, and wraps Pink/Yellow/Red in user_links.html
Or you can put Pink/Yellow/Red in {% block content %} if user_links.html and use {{ block.super }} in user_detail.html
links.html
{% extends "base.html" %}
{% block content %}
Yellow
Pink
Green
{% endblock %}
user_detail.html
{% extends "user_links.html" %}
{% block content %}
{{ block.super }}
<h2>{{ object.username }}'s Profile</h2>
{% if object.userprofile.bio %}
{{ object.userprofile.bio }}
{% endif %}
{% endblock %}
Place div after </p> in base.html
<h1>Cool App</h1>
<div class="navbar">
<p>
HOME |
{% if user.is_authenticated %}
LOGOUT
{% else %}
LOGIN
{% endif %}</p>
</div>
Try this in user_links.html
{% extends "base.html" %}
{% block content %}
Yellow
Pink
Green
{% endblock %}

How to display layout content in Twig template based on a view

I have some content in my layout that are not supposed to be displayed in some pages.
E.g.: When a user is registering for the site my default frontpage sidebar should not be displayed:
<!DOCTYPE html>
<html>
<head>
{% block head %}
<link rel="stylesheet" href="style.css" />
<title>{% block title %}{% endblock %} - My Webpage</title>
{% endblock %}
</head>
<body>
<div id="content">
<div id="sidebar">
{% block sidebar %}
{% render "/layout/sidebar" %}
{% endblock %}
{% block content %}{% endblock %}
</div>
</div>
<div id="footer">
{% block footer %}
© Copyright 2011 by you.
{% endblock %}
</div>
</body>
</html>
In the above code:
{% block sidebar %}
should display some advertising instead!
So:
Something like:
{% if SOMEVIEW == TRUE %}
{% block sidebar %}
{% else %}
{% block advertising %}
{% endif %}
What expression could I use in my IF to accomplish that job?
Thanks in advance
You can look at
How to check if an user is logged in Symfony2 inside a controller?
and http://symfony.com/doc/current/book/security.html#access-control-in-templates
In the view you can use {{ is_granted('IS_AUTHENTICATED_FULLY') }} to check if a user is logged in.
Hope it's helpful.
Best regard.
I came accross to the solution here http://symfony.com/doc/current/cmf/bundles/core.html#twig:
app.request.attributes.get('_template').get('name')
will return the route name so that I can handle it inside my twig files.

Issue trying to customizing the admin in Django

In order to add some links in the admin of my site I added a custom block (surrounded in red in the images below) to admin/base.html and set it in admin/base_site.html.
The issue is that it's shown in all admin pages (eg connexion screenshot shown below), while I'd like to show it only in the site admin first page.
Anybody could help?
admin/base.html
...
<!-- Content -->
<div id="content" class="{% block coltype %}colM{% endblock %}">
{% block pretitle %}{% endblock %}
{% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %}
{% block content %}
{% block object-tools %}{% endblock %}
{{ content }}
{% endblock %}
{% block sidebar %}{% endblock %}
{% block myblock %}{% endblock %} <!-- custom block -->
<br class="clear" />
</div>
<!-- END Content -->
....
admin/base_site.html
....
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans 'Administration de Django' %}</h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% block myblock %}
<div style="margin-top:160px;">
<div style="font-size:18px; color:#666666;font-weight:bold;margin-bottom:10px;">Rapports</div>
Rapports journaliers<br/>
Rapports mensuels
</div>
{% endblock %}
....
Site admin
Connexion
Then you are better off overriding admin/index.html
For this purpose I would like to recommend to you django-admin-tools application. As documentation says:
django-admin-tools is a collection of extensions/tools for the default
django administration interface, it includes:
a full featured and customizable dashboard;
a customizable menu bar;
tools to make admin theming easier.
Please join the mailing list if you want to discuss of the future of django-admin-tools.