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 %}
Related
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
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 %}
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.
I am fairly new to django and am trying out template-inheritance but not able to get it work. I cannot get all the blocks in a page to be displayed simultaneously. Not sure if I am missing something in urls, views or settings. I am using Python 3.6 in venv / Django 2.0.4 on PyCharm
Details of my example below - myhome being project name and smarthome being app name
Folder Structure
base.html
navtopbar.html
navsidebar.html
smarthome urls.py
smarthome views.py
-- Initially I had this as base.html but based on advice in thread below, changed to navtopbar. But then not sure how to get application to display navsidebar simultaneously
settings
I followed the advice in this thread but not able to get it to work yet. Appreciate any help here.
First of all careful with naming!
You are rendering your view in navtopbar.html
In navtopbar.html you have only override navtopbar block so only that block will replaced.
Djnago template works as below:
base.html
{% block body %} base {% endblock %}
{% block content %} base {% endblock %}
Now if you render home.html from view it should be:
home.html
{% extends 'base.html' %}
<!-- the blocks you override here only replaced -->
{% block body %}
home
{% endblock %}
As above html you have only overridden one block which results to override one block and other remains unchanged. the if you want to override {% block content %} you need to override in same html as below:
home.html
{% extends 'base.html' %}
<!-- the blocks you override here only replaced -->
{% block body %}
home
{% endblock %}
{% block content %}
home content
{% endblock %}
If you want to include content from another html you can include it with include tag
consider below file:
content.html
<h3>This is common content</h3>
now you can include this in your home.html as below:
home.html
{% extends 'base.html' %}
<!-- the blocks you override here only replaced -->
{% block body %}
home
{% endblock %}
{% block content %}
{% include 'content.html' %}
{% endblock %}
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.