Skip to main content

Jinja theme capability

Project description

Fastapi Jinja theming system.

Include Block Tag

This template system heavily uses the include_block tag. This tag will include an html file as a block. This tag can be overridden with an html file matching the name or by a block tag matching the base name.

Create a base for your theme

{# theme_templates/theme/base.html #}
<html>
<body>
{% include_block "theme/sidenav.html" %}

{% block contents %}
<h1>Hello World!</h1>
{% endblock %}
</body>
</html>

Normal navigation for your theme

{# theme_templates/theme/sidenav.html #}
<ul>
  <li><a href="/">Home</a></li>
  <li><a href="/page1">Page 1</a></li>
  <li><a href="/page2">Page 2</a></li>
</ul>

Override with block

Override navigation by using a block. The block name will be the same as the base html filename. Note: different templates directory

{# templates/main.html #}
{% extends "theme/base.html" %}

{% block sidenav %}
<ul>
  <li>Hello</li>
</ul>
{% endblock sidenav %}

Override with HTML file

Alternatively you can override by using an html file. Note: different templates directory

{# templates/theme/sidenav.html #}
<ul>
  <li><a href="/">Home</a></li>
  <li><a href="/link">Link to my other site</a></li>
</ul>

Fastapi using the templates

from fastapi import FastAPI, Request
from justengel_theme import ThemeTemplates

MYD_DIR = os.path.dirname(__file__)

# Search for project files first
project_dir = os.path.join(MY_DIR, 'templates')
templates = ThemeTemplates(project_dir)

# Search for theme files if project files are not found
theme_dir = os.path.join(MY_DIR, 'theme_templates')
templates.add_directory(theme_dir)

app = FastAPI()

@app.get('/')
def index(request: Request):
    return material.TemplateResponse('main.html', {'request': request})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

justengel_theme-0.0.3.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

justengel_theme-0.0.3-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file justengel_theme-0.0.3.tar.gz.

File metadata

  • Download URL: justengel_theme-0.0.3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

File hashes

Hashes for justengel_theme-0.0.3.tar.gz
Algorithm Hash digest
SHA256 99b4a8f5d93e74857f793dca9146f0dc2eb64fbf6da3335ecaf340225b6ea83e
MD5 310d32615e76c8cd0c54e737974590b8
BLAKE2b-256 58e41856ad0bbb8e3a7793ed9b03c6a435698d800bf7e4de92c26eb25abeb11c

See more details on using hashes here.

File details

Details for the file justengel_theme-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: justengel_theme-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

File hashes

Hashes for justengel_theme-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5fc50835e46a589bf5558d4eb2063c2af9c1376b2b7b11235ce0949020c13a46
MD5 8d7580dd34f28e927bdff81a4dabc7c1
BLAKE2b-256 2f108cee548d630bb23f025f993897b4c98264f2099923eeee6ef9b311b620d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page