Static css file not loading in Django admin - python

I'm trying to load my own css file to replace base.css in order to customize Django Admin
{% extends "admin/base.html" %}
{% load static %}
{% block title %}VSPM{% endblock %}
{% block branding %}
<h1 id="site-name">{{ site_header|default:_('Django administration') }}</h1>
{% endblock %}
{% block stylesheet %}{% static "admin/css/theme.min.css" %}{% endblock %}
{% block nav-global %}{% endblock %}
But the css file isn't loading in Django admin. What am I doing wrong?

{% block extrastyle %}{% static "admin/css/theme.min.css" %}{% endblock %}
Change your block name and try

Go to your project.
Copy this folder /virualent_path//lib/python3.6/site-packages/django/contrib/admin/static/admin to 'static' folder of your project.
Add this string to the settings.py: STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
Then run this command: python3.6 manage.py collectstatic

Related

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

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

base.html template only displays 1 block of code instead of multiple

I'm creating my base.html file and for some reason only one block is displaying in my base.html file at a time. I am trying to include a nav bar, a footer, and some content in base.html but it will only display one block at a time.
I have a feeling it has something to do with my view class because I am only including one file at a time, however I'm fairly new to starting a Django project and I don't know the common procedure to set up a base.html file.
base.html:
{% block nav_bar %}{% endblock %}
{% block content %}No Content to Show!!{% endblock %}
{% block footer %}No Footer Available!!{% endblock %}
views.py:
from django.views.generic import TemplateView
class HomeView(TemplateView):
template_name = 'home.html'
Hoping to have all blocks show up on the page at once!
EDIT: home.html is my homepage content page.
If you are extending the 'home.html' from 'base.html'. Please check if you have the right structure as mentioned below and I recommend you to use spaces between the '}' or '{' and what will come after them.
base.html:
<!DOCTYPE html>
<body >
{% block nav_bar %}{% endblock %}
{% block content %}{% endblock %}
{% block footer %}{% endblock %}
</body>
</html>
home.html :
{% extends "base.html" %}
{% block nav_bar %} {% endblock %}
{% block content %} No Content to Show!! {% endblock %}
{% block footer %} No Footer Available!! {% endblock %}

Why Django show me the path to the template but do not load the template himselfe into the page?

In the static folder of my DjangoServer is located a template of the default webpage. It's decorated with some template blocks.
If I load this template file, the path to the template is shown in the browser, it looks like, that the code is not loaded.
If I store the template in an app/template folder and I extend this file. It works very well. I use the tutorial of Django but it still not working.
Settings.py
django.contrib.staticfiles is added to INSTALLED_APPS
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
projectRootFolder/static/html/basePage.html
{% load static from staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
{% block head %}
<title>{% block title %}My amazing site{% endblock %}</title>
{% endblock %}
</head>
<body>
{% block body %}
<header>
{% block header %}
<header> -- HEADER BANNER --</header>
{% block menu %}<nav></nav>{% endblock %}
{% endblock %}
</header>
<section>
{% block section %} SECTION {% endblock %}
</section>
{% block footer %}
<footer> -- FOOTER --</footer>
{% endblock %}
{% endblock %}
</body>
<script type="text/javascript" src="{% static 'angularjs/SOME_ANGULAR_FILES_LOADED.js' %}"></script>
</html>
app/template/app/index.html from an app
{% load static from staticfiles %}
{% static "html/basePage.html" %}
{% block menu %}<nav>App A</nav>{% endblock %}
{% block section %} Lorem Ipsum{% endblock %}
app/views.py
from django.template import loader
from django.shortcuts import render
from django.http import HttpResponse
# PAGE CALLS
def index(request):
template = loader.get_template('mainControll/index.html')
context = {}
return HttpResponse(template.render(context, request))
Output
What is the mistake i've made? How can I load this template correctly?
Warning, this answer assumes your goal for asking the question is to get things to work, instead of helping you troubleshoot a probable permission problem just so that you can run into another problem. That is, I'm assuming your end goal is not a html document inside a non-html document.
What can you do to get your output to work:
It looks like you want to include a template into another template, you can do that with {% extends "basePage.html" %}. Your template does then need to be at a location where templates are found, not where static pages are found.
E.g. If your app is called 'myapp' then under myapp/templates/ is a one possible place, assuming the TEMPLATES setting has APPDIRS = True
This would mean changing index.html to be
{% extends "basePage.html" %}
{% block menu %}<nav>App A</nav>{% endblock %}
{% block section %} Lorem Ipsum{% endblock %}
See https://tutorial.djangogirls.org/en/template_extending/ for example of this and https://docs.djangoproject.com/en/1.11/topics/templates/#configuration for configuring things to that your basePage.html can be found

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.

Categories