Easy to use breadcrumbs for webpages using Flask.
Project description
QDCrumbs
Quick & Dirty Breadcrumbs
Description
This package provides a simple way to add dynamic breadcrumbs to a Flask application. The breadcrumbs can easily be used in a jinja2 template.
QDcrumbs work in both the main Flask application and in Flask Blueprints, and currently support a single variable page, simply import qdcrumb from qdcrumbs and follow the examples below.
Get started:
Getting started with qdcrumbs is easy! Import the qdcrumb object and follow the example below.
Examples
The following examples work both in the main Flask app and Blueprints!
Importing qdcrumbs:
from flask import Flask
from qdcrumbs import qdcrumb
Standard Usage:
@app.route('/')
def my_page():
x = qdcrumb.get_crumbs()
return render_template('/my_page.html', breadcrumbs=x)
With a variable name:
@app.route('/path/to/<var>')
def my_page(var):
x = qdcrumb.get_crumbs(var)
return render_template(f'/path/to/{var}.html', breadcrumbs=x)
IMPORTANT!
qdcrumb.get_crumbs() must be called from within a function that points to a resource's route: i.e. a function with the route decorator (@app.route | @blueprint.route). This is because the url is resolved via Flask using url_for() which takes the name of the function that was decorated.
Breadcrumbs are provided as a list of the Breadcrumb class and have the following attributes:
- url --> Path to the current page/resource & preceding pages.
- text --> Name of the current page/resource.
Changing app name
By default, QDcrumbs assumes your Flask application has the name 'app' and was initialized in the following manner:
app = Flask(__name__) #__name__ being 'app'
If your app uses a different name, you must change it on the qdcrumb object in your main python file:
qdcrumb.set_app_name('your_app_name')
HTML
The breadcrumbs do not provide the site's root directory, this can be added manually trivially (see html jinja2 template example below).
<div>
<!--
Include a static link to the site root (Index.html)
(The Application's root must be added manually)
-->
<a href="{{ url_for('index.html')}}">Index</a>
<!--Loop through the breadcrumbs to this resource-->
{%- for breadcrumb in breadcrumbs -%}
<a href="{{ breadcrumb.url }}"> / {{ breadcrumb.text }}</a>
{%- endfor -%}
</div>
Changelog
0.0.2
- Removed a print statement when accessing resources on a web page.
0.0.1
- First version released.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file qdcrumbs-0.0.2.tar.gz
.
File metadata
- Download URL: qdcrumbs-0.0.2.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 977fe69e1e13bb30d0025f083f736e7015690c846b9027a6b514f7c8c615f01c |
|
MD5 | caf341712ba24a6b13cf3d526f59dfcb |
|
BLAKE2b-256 | 9f73a461ad391f51a8a65f46b723c8a5caa782aa62fb01c07876d304a7b47d50 |
File details
Details for the file qdcrumbs-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: qdcrumbs-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b25803c566a0f58d311968459dbb9e9c90e4ac272662d6112d552db146c62805 |
|
MD5 | 0392879ef5f93d7a82e226b96ce56c01 |
|
BLAKE2b-256 | a6a1a00aa05e42661d94d324e7807e42c2218c8f415737c10967f5f8e76074ea |