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
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, Wordpress
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),
)
)
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
Hashes for canonicalwebteam.blog-6.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a39dbdbaf97f2e8eb5c5e43efb692d4c2f779eaea2c319e42b2c043856629974 |
|
MD5 | 4296cdd0e4d6987def5452e309f49ab8 |
|
BLAKE2b-256 | a6776dc07168abf30aa3f0ae9233ac76cb16ae72a12ffc3547ef2a17462afa0b |
Hashes for canonicalwebteam.blog-6.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45a1e8c4dd4e18c4c677d48ad0fe60ed76e7c0c2ffb563a9395ad03e86f455c8 |
|
MD5 | 6e4e546cc20a8be09fbf1040eb575764 |
|
BLAKE2b-256 | 753a0d319bb0f2dd8f4c3e9338cbc9568e816721b6ea5b58523c6ed9d62cd486 |