I'm trying to use flask-bootstrap in my project and I want to extend my html with bootstrap/base.html , but It can't recognise the file. Here is the Python code (only the part that matters):
from flask import Flask, render_template
from loggin_form import LoggingForm
from flask_bootstrap import Bootstrap
app = Flask(__name__)
app.secret_key = "123string"
Bootstrap(app)
and here is the html:
{% extends "bootstrap/base.html" %}
{% block title %}This is an example page{% endblock %}
{% block navbar %}
<div class="navbar navbar-fixed-top">
something
</div>
{% endblock %}
{% block content %}
<h1>something else</h1>
{% endblock %}
I have tried many things, but not much seems to work. as you can see I have correctly passe the app inside the bootstrap class (it's usually the solution that people with similar problems found) but I already have done it. Also I have correctly installed Flask-Bootstrap and the path directory of bootstrap/base.html is as followed : venv/lib/python3.10/site-packages/flask_bootstrap/templates/bootstrap/base.html
the exact warning that pycharm throws at me: Unresolved template reference '"bootstrap/base.html"'
it does that even if I put the full path directory.
I thank you in advance for your answers guys.
Ps: I am using jinja 2.11.3 and Flask 1.1.4
I found out that the folder inside the venv where the base.html was had to marked as a template folder. Then Pycharm easily recognised it
You need to mark the flask-bootstrap templates folder as a template folder.
In Settings, go to Project Structure and navigate to venv/lib/site-packages/flask_bootstrap. Right-click on the templates folder and mark it as Templates. Apply this and it should work.
Related
I'm writing code for an app can be installed like a module on multiple django projects, each of which could each be configured differently. I'm looking for a way to conditionally load a package depending on how the project is configured.
If a specific package is listed in INSTALLED_APPS in the settings.py file of the project, then load the package with {% load my_package %}.
I'm envisioning something like:
{% if package_is_installed %}
{% load package %}
{% endif %}
<body>
{% if package_is_installed %}
{% use part of the package %}
{% endif %}
</body>
Is this possible with tags or some other html or javascript implementation?
You'd be better off keeping logic outside of the template files & having different versions of the templates.
To do this in a template means writing some python for a filter or a template tag, so it's much better practice to keep the logic in the view that conditionally selects the template.
if 'myapp' in settings.INSTALLED_APPS:
temmplate_name = 'myapp.html'
else:
template_name = 'base.html'
I'm using auto generated HTML which has been saved to a file and then read in again to use as part of a page in a django template.
In order to do this I have used:
{% autoescape off %}
{{ my_html }}
{% endautoescape %}
However, in the my_html variable, I have some static content. This comes in the form of something like this:
<img src="{% static "img/tree_report.png" %}" width="12px" height="12px"/>
My issue is that the static content is not displayed. I get:
http://127.0.0.1:8000/%7B%%20static 404 (in the browser error report)
I read something about get_static_prefix in another question but that doesn't solve my problem because I just get this instead:
GET http://127.0.0.1:8000/%7B%%20get_static_prefix%20%%7Dimg/tree_report.png 404 (Not Found)
I also tried endautoscape turning on and off periodically in my_html in the saved HTML variable. That also didn't work.
Should I be autogenerating the development and production static files paths for my_html or is there a more elegant solution to this problem?
Any suggestions are most welcome.
Thanks.
I have downloaded the following templates from admin.contrib: base.html, base_site.html and index.html.
I would like to extend index.html, but no matter what I do it does not seem to work.
In settings.py, I have declared the name of my app to override the order in which the admin files are render. So, I can edit the actual files and content does change when I run the server.
But, I create a file in the directory templates/admin/foo.html.
The code with foo.html is:
{% extends "admin/index.html" %}
{% block something %}
<p>Hello</p>
{% endblock %}
And I have change the file templates/admin/index.html to have {% block something %}{% end block %}
When I run the server, the content of foo.html does not display.
Do I need to add foo.html to my urls.py and create a function within views.py to render the content?
Any help would be greatly appreciated.
Foo.html is not recognized by Django admin. If you want to customize admin/index.html, do your changes in admin/index.html.
If you want to use a separate file, include it inside the admin/index.html like this:
{% include "foo.html" %}
Hope it helps!
How do you enable an archives tab on a pelican powered blog?
I see from the docs that it is a direct template by default, but it isn't showing up on my blog. Is there some additional field to enable it? I couldn't find any mention of it in the docs or tutorials, so I'm assuming I've missed something obvious.
Not sure if you ever resolved this; I was having the same issue as you with pelican's bootstrap3 theme. For some reason, setting a value for YEAR_ARCHIVE_SAVE_AS was not working.
After looking at the theme's base.html file, I got it working by adding the following to pelicanconf.py:
ARCHIVES_SAVE_AS = 'archives.html'
Lines 156-158 from my base.html file:
{% if ARCHIVES_SAVE_AS %}
<li><i class="fa fa-th-list"></i><span class="icon-label">{{ _('Archives') }}</span></li>
{% endif %}
I'm trying to add features to Django 1.2 admin's main page.
I've been playing with index.html, but features added to this page affect all app pages.
Any ideas on what template I'm supposed to use?
Thanks loads!!
You can use template hierarchy like:
index.html
...
{% block content %}
...
{% block mycontent %}My custom text{% endblock %}
...
{% endblock %}
app_index.html
...
{% block mycontent %}{% endblock %}
..
According to http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template you will want to override admin/app_index.html
I have done this by modifying the admin/index.html template. You may also need to modify admin/base_site.html (depending on what you want to do, exactly).
These templates are found in the django/contrib/admin/templates/admin folder in a Django installation.
Update: That's exactly what I've done, see the screenshot fragment below. The section marked in red is the section I added, via HTML in admin/index.html. However, you don't say which version of Django you're using - my example is from a 1.0 installation.