how to completely remove the recent action panel from Django admin UI - python

how to completely remove the recent action panel from Django admin UI
I have done a lot of searching and all leads to how to clear the data in the panel from the database .. but what am looking to do is completely remove the panel from my admin Userinteraface .. any help on how to do this?
what I've tried :
tried to override the base_site.html for the admin and it worked for override colors and styles and other blocks but not working with the sidebar block
{% extends "admin/base.html" %}
{% load i18n static %}
{% block title %}{{ title }} | {% trans "G-Attend" %}{% endblock %}
{% block extrastyle %}
<link rel="stylesheet" type="text/css" href="{% static 'custom_admin_styles/admin_override.css' %}">
{% endblock %}
{% block branding %}
<h1 id="site-name">
<b style="color: #1f76bc;size: 80;">
G
</b> Attend </h1>
{% endblock %}
{% block sidebar %}
<div id="content-related">
</div>
{% endblock %}
{% block nav-global %}{% endblock %}

The right solution for this was like :
creating a file called index.html inside my templates/admin/ directory , then inside the HTML file I used this code :
{% extends "admin/index.html" %}
{% block sidebar %}
{% endblock %}
so I need to extend index.html instead of base_site.html

To override the Django admin side bar
You nee to extends admin/base_site.html
{% extends "admin/base_site.html" %}
{% load i18n static %}
<!-- -->
{% block sidebar %}
<div id="content-related">
Your custom side bar here.
</div>
{% endblock %}
NB : Inside your templates folder, you should have created an admin subfolder. And place the custom .html file in it.
More info Here

Related

How can I use template blocks in django?

I'm trying to load a header template into my index with {% block %} but I can't get it to load
index.html
<body>
<header>
{% block header %}{% endblock %}
</header>
<h1>Hello</h1>
</body>
header.html
{% extends "index.html" %}
{% block header %}
<div class="header">
<i class="fas fa-archive"></i>
<i class="fas fa-home"></i>
<h1>hey</h1>
</div>
{% endblock %}
views.py
def index(request):
categories = Category.objects.all()
context = {'categories': categories}
return render(request, 'category/index.html', context)
The app is installed in the settings.
To get things to work the way you wanted you would need to make header.html the base template then extend index.html off of it. This is because header.html is only substituting in {% block header %} when you render header.html. Index.html doesn't see any of these substitutions when rendered. You may want to make the header.html file a static file and load it in that way. Similar to how you would with css.
To achieve what you want to you should render header.html now, check django docs.
It's better to have a layout and then put the header block inside it.
layout.html
...
<body>
<header>
{% block header %}{% endblock %}
</header>
<h1>Hello</h1>
{% block content %}{% endblock %}
<footer>
{% block footer %}{% endblock %}
</footer>
</body>
...
index.html
{% extends "layout.html" %}
{% block header %}
the header
{% endblock %}
{% block content %}
here the content
{% endblock %}
{% block footer %}
here the footer
{% endblock %}
Now you can render the index.html in your view

what is {% block content %} and {% endblock content %} for in Django?

so I just started reading a book on Django (for beginners) and I came across the following code snipet:
<header>
Home | About
</header>
{% block content %}
{% endblock content %}
Could anyone possibly explain to me what is the use of {% block content %} and {% endblock content %}? Thank you very much in advance!
block is used for overriding specific parts of a template.
In your case, you have a block named content and this is supposed to be overridden by children that inherit from this template.
From the examples at The Django Docs
Template to be extended, named base.html
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
</head>
Overriding Child template
{% extends "base.html" %}
{% block title %}My amazing blog{% endblock %}
"My amazing site" will be overriden by the child and then display "My amazing blog"
That's where the power of the templates comes from in a sense.
You can create a hierarchy of templates so start with base.html which might be like you've got above;
<body>
{% block content %}
{% endblock content %}
</body>
Then you can create any other template, home.html for example, and do something like;
{% extends "base.html" %}
{% block content %}
<h1>Welcome</h1>
<p>This is the home page</p>
{% endblock content %}
Then you'd reference home.html in django and it'd include the markup from base.py with the content defined in home.html.
That's the basics, but if you put some templates together using blocks you'll pick it up.
For example, you have code excerpts from 2 files:
base.html:
<body bgcolor="cyan">
{% block content %}
{% endblock %}
</body>
home.html:
{% extends 'base.html' %}
{% block content %}
<h1>Hello World from Abhishek</h1>
{% endblock %}
here in home.html, the attributes of base.html will be extended but by using {% block content %} and {% endblock %} you will be able to override the code block of home.html upon the attributes of base.html
This is Jinja template for a dynamic website.

Django CMS Apphook - no app content is shown on page

I integrated an app into the cms using the documentation. All ist set but the CMS doesnt show the app content. It seems base.html will not show the content of my app.
Could it be my app-used template ?
list.html
{% extends CMS_TEMPLATE %}
{% load render_table from django_tables2 %}
{% load cms_tags sekizai_tags staticfiles %}
{% block main %}
{% addtoblock "css" %}<link rel="stylesheet" href="{% static "django_tables2/themes/paleblue/css/screen.css"%}">{% endaddtoblock %}
{% render_table doctor_htmltable %}
{% endblock main %}
I figured it out. although I still do not find it mentioned anywhere in the documentation.
In my base.html a block is defined:
{% block content %}{% endblock content %}
and so everything the app should display must also be include into a block with the same name
{% block content %}
....(see lines in question)
{% endblock content %}

How to make Django template recognize load tag upon inheriting from base template

I have the following base.html
{% load static from staticfiles %}
<html>
<title>COOL| {% block title %} Sometitle {% endblock %}</title>
<body>
<!--- BEGIN INSERT CONTENT FOR OTHER PAGE HERE-->
{% block 'body' %}
{% endblock %}
And I have somefile.html which are wrapped by the above.
{% extends 'base.html'%}
{% block title %} Contact {% endblock %}
{% block 'body' %}
<h1> CSV </h1>
{% endblock %}
The message I get is this:
Invalid block tag: 'static', expected 'endblock'
I expect somefile.html will inherit {% load static from staticfiles %} from base.html. But it doesn't. What's the right way to do it?
You should load tags in each template.

Jinja2 block nesting issue

I am using jinja2 as a template language in my project. Here is simplified templates structure:
base.html:
{% block content %}{% endblock %}
{% block sidebar %}{% endblock %}
content.html:
{% extend 'base.html' %}
{% block content %}
<div class="content">
Content
{% block sidebar %}
<div class="sidebar">Sidebar</div>
{% sidebar %}
</div>
{% endblock %}
And the result of content.html render:
<div class="content">
Content
<div class="sidebar">Sidebar</div>
</div>
<div class="sidebar">Sidebar</div>
As you may see, sidebar is present twice at rendered content.html.
Question:
Is there a way to avoid appearance of the sidebar in content, leaving {% block sidebar %} inside {% block content %} ?
I think your content.html template is invalid - you're clearly positioning sidebar related content inside the content block, so it will allways appear there. Also, your base.html seems invalid as well, it should look more like:
{% block content %}{% endblock %}
{% block sidebar %}{% endblock %}

Categories