Flask extension to add a nice blog to your website
Project description
Canonical blog extension
This extension allows you to add a simple frontend section to your flask app. All the articles are pulled from Canonical's Wordpress back-end through the JSON API.
This extension provides a blueprint with 3 routes:
- "/": that returns the list of articles
- "/": the article page
- "/feed": provides a RSS feed for the page.
Installation
To install this extension as a requirement in your project, you can use PIP;
pip3 install canonicalwebteam.blog
See also the documentation for pip install.
Usage
Local development
For local development, it's best to test this module with one of our website projects like ubuntu.com. For more information, follow this guide (internal only).
Templates
The module expects HTML templates at blog/index.html
, blog/article.html
, blog/blog-card.html
, blog/archives.html
, blog/upcoming.html
and blog/author.html
.
An example of these templates can be found at https://github.com/canonical-websites/jp.ubuntu.com/tree/master/templates/blog.
Usage
In your app you can then do the following:
import flask
import talisker.requests
from flask_reggie import Reggie
from canonicalwebteam.blog import BlogViews, build_blueprint, BlogAPI
app = flask.Flask(__name__)
Reggie().init_app(app)
session = talisker.requests.get_session()
blog = build_blueprint(
BlogViews(
api=BlogAPI(session=session),
)
)
app.register_blueprint(blog, url_prefix="/blog")
You can customise the blog through the following optional arguments:
blog = build_blueprint(
BlogViews(
blog_title="Blog",
blog_path="blog",
tag_ids=[1, 12, 112],
exclude_tags=[26, 34],
per_page=12,
feed_description="The Ubuntu Blog Feed",
api=BlogAPI(
session=session,
use_image_template=True,
thumbnail_width=330,
thumbnail_height=185,
),
)
)
Testing
All tests can be run with ./setup.py test
.
Regenerating Fixtures
All API calls are caught with VCR and saved as fixtures in the fixtures
directory. If the API updates, all fixtures can easily be updated by just removing the fixtures
directory and rerunning the tests.
To do this run rm -rf fixtures && ./setup.py test
.
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 canonicalwebteam.blog-6.4.2.tar.gz
.
File metadata
- Download URL: canonicalwebteam.blog-6.4.2.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1230cf0e18eadaeb0f257031df2e7640d27c737e165a4a0bd4accef892e937a0 |
|
MD5 | d70827cb38292a5ed5905513d1a24288 |
|
BLAKE2b-256 | 3079042269a81ccfa1d39efea7bd87ffcdadcd9dc8c64c82e0c0215b133a2d39 |
File details
Details for the file canonicalwebteam.blog-6.4.2-py3-none-any.whl
.
File metadata
- Download URL: canonicalwebteam.blog-6.4.2-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b686fbbc8e30e1a467d6199bf8a1bf9e882cf29a8be7c6f24a5d09d5255a68c6 |
|
MD5 | ab3a2dd157ed0cc48b54ff7ee6fabac5 |
|
BLAKE2b-256 | 395907d9d07f5ac1e99b7ca0f51e98576663f8a1b7e9cab6ac189e4eb60c2d65 |