No content visible in django-bootstrap3 - django

I am using Django 1.9 and demo template structure to display home.html.
I have included the following in the base.html file:
{% block bootstrap3_content %}
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
...
</div>
</nav>
<div class="container-fluid">
{% autoescape off %}{% bootstrap_messages %}{% endautoescape %}
{% block content %}(no content){% endblock %}
</div>
{% endblock %}
Navbar shows successfully but I do not get the Bootstrap message in the container below?
I am a new user to Django and this App as well. Please help!
Edit1:
bootstrap.html extends bootstrap3.html; base.html extends bootstrap.html; home.html extends base.html.
home.html
{% block title %}My_title{% endblock %}
{% block content %} This is <em>bootstrap3</em> for <strong>Django</strong>.
{% endblock %}
I get the title in the navbar but no message inside content block.

Make sure that you have
{% load bootstrap3 %}
at the top of your page since you are using this module. Make sure that you have
'bootstrap3',
in your installed apps.
From your code it looks like you are extending a template. If you are, be sure to have a
{% extends FooTemplate.html %}
in case you are loading boostrap3 in the parent template.

Related

Unable to load multiple content blocks in Django 4.0 using TailwindCSS

Folder Structure:
mysite
-theme
--templates
---main_base.html
---theme_footer.html
---theme_menu.html
-home
--templates
---home
----main.html
main.html:
{% extends "main_base.html" %}
{% block content %}
blah blah
{% end content %}
main_base.html:
{% load static tailwind_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
{% tailwind_css %}
</head>
<body class="bg-blue-100">
<nav>
{% block navbarn %}
{% endblock %}
</nav>
{% block content %}
{% endblock %}
<footer>
{% block footer %}
{% endblock %}
</footer>
</body>
</html>
theme_menu.html:
{% extends "main_base.html" %}
{% block navbarn %}
home
{% endblock %}
theme_footer.html
{% extends "main_base.html" %}
{% block footer %}
<h1>this is a footer</h1>
{% endblock %}
So I was able to setup Django with Tailwind following the instructions on the plugin page. But I can't get the base theme to show multiple blocks. It doesn't show the menu nor the footer, just the base html template with content from main.html. Can't get it to work!
If anyone else is running into this issue, you can't use multiple extends. You instead, include it in your base.
For me, I removed the {% extends %} tags from the ancillary pages, and then included them in my theme_base.html like:{% include 'theme_footer.html' %}

Django templates - include and repeat the block contents

In my home.html page, I am trying to include a header.html file along with extending base.html. Following is my code
{% extends "base.html" %}
{% block body %}
{% include 'header.html' %}
# including the block navigation from header.html
<nav id='header-nav'>{% block nav %} {% endblock %}</nav>
# including the block image from header.html
<div id='header-img'>{% block image %} {% endblock %}</div>
# Reusing the same navigation in footer from header.html
<div id='footer-nav'>{% block nav %} {% endblock %}</div>
{% endblock %}
Home.html looks like the following
{% block image %}<h1>I am image</h1>{% endblock %}
{% block nav %}<h1>I am navigation</h1>{% endblock %}
However, it returns an error - ''block' tag with name 'nav' appears more than once'.
Why is that? Is there any solutions to this?
Regards
You included {% block nav %} twice in the same template. That's why it's throwing the error. Maybe you meant to do {% block footer %}?
{% extends "base.html" %}
{% block body %}
{% include 'header.html' %}
# including the block navigation from header.html
<nav id='header-nav'>{% block nav %} {% endblock %}</nav>
# including the block image from header.html
<div id='header-img'>{% block image %} {% endblock %}</div>
# Name this block something else i.e add a new block in header.html
# and this error should clear up.
<div id='footer-nav'>{% block footer %} {% endblock %}</div>
{% endblock %}

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) %}}

Djangocms template not showing up

I have a basic DjangoCMS up and running.
base.html contains:
{% block content %}{% endblock content %}
I also have feature.html:
{% extends "base.html" %}
{% load cms_tags %}
{% block title %}{% page_attribute "page_title" %}{% endblock title %}
{% block content %}
<div>
{% placeholder "feature2" %}
</div>
<div class="jumbotron"">
{% placeholder "feature" %}
</div>
<div>
{% placeholder "content" %}
</div>
{% endblock content %}
I added the "feature2" placeholder in the above, and it correctly displays for editing on the site.
I then added a new line to base.html:
{% block base_logo %}{% endblock base_logo %}
and created a new file, base_logo.html:
{% extends "base.html" %}
{% load cms_tags %}
{% block base_logo %}
<div>
{% placeholder logo %}
</div>
{% endblock base_logo %}
I expected this to also appear on the site for editing, but it doesnt. I have added the base_logo.html to the CMS_TEMPLATES in settings.py and TEMPLATE_DIR is also pointing correctly.
What else do I need to do for Djangocms to pick up my new template?
Take a look at template inheritance.
You're trying to use two {% extends %} tags, which won't work. You should use the {% include %} tag for base_logo, because it seems you'd want to include this in many templates. This question provides more info.

extend other app to my template working

I want to extend an other template to my blog.html, no matter have i try to extend this, it doesn`t work .
blog/index.html
{% block nav %}
<ul id="nav">
<li>{% block nav-blog %}Blog{% endblock %}</li>
<li>{% block nav-photo %}Photo{% endblock %}</li>
</ul>
{% endblock %}
<div class="news">
{% block polls %}
{% extends 'polls/index.html' %}
{% endblock %}
<div>
polls/index.html
{% if latest_poll_list %}
<ul>
{% for poll in latest_poll_list %}
<li>{{ poll.question }}</li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
Usually extends has to be stuck at the top of the template and not somewhere in the template.
In the template you use the tags that you have set up in the base templates.
You need to make sure you're doing two things here:
Declare a "nav" block in your index.html. This will let django know the part of your index html you wish to have overwritten when a template extends it. Anything you put inside the "nav" block in index html will be considered default content.
You need to use the "extends" template tag at the beginning of your blog.html so django knows the template you'd like to extend.
Like this:
index.html
{% block nav %}
<div>
Some default html here..
</div>
{% endblock %}
And then blog.html
{% extends index.html %}
{% block nav %}
<div>
This is what will render
</div>
{% endblock %}
Also, you're going to want to test index.html before trying to extend it to verify that django is finding that template. If it isn't then you need to add the directory that it is found in to the TEMPLATE_DIRS array in your settings.py file.