Skip to main content

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, 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,
        ),
    )
)

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

canonicalwebteam.blog-6.2.3.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

canonicalwebteam.blog-6.2.3-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file canonicalwebteam.blog-6.2.3.tar.gz.

File metadata

  • Download URL: canonicalwebteam.blog-6.2.3.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for canonicalwebteam.blog-6.2.3.tar.gz
Algorithm Hash digest
SHA256 32f7db6873a8ebcca49027fd49744aed91ae10699c1af317b0ecccdb3be4ea5d
MD5 ed2c2f83c1b45b26cd04d8bdbb79bdb8
BLAKE2b-256 91e4a3487054c64fd69a8da780b2c659e38be56ae73aa9d75475a8ebe5767a36

See more details on using hashes here.

File details

Details for the file canonicalwebteam.blog-6.2.3-py3-none-any.whl.

File metadata

  • Download URL: canonicalwebteam.blog-6.2.3-py3-none-any.whl
  • Upload date:
  • Size: 14.3 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/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

File hashes

Hashes for canonicalwebteam.blog-6.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 815ce9a1f809d989ee2cd8f551abf60e2cfb39f1d431431bf442f8806649e0b1
MD5 eafd1373867b6e9a94ad41a1a8c62fbc
BLAKE2b-256 120e334beb92ef9681d8c6f7a655f5a2823e8098236baaf6a25c06bfbf0bb3d1

See more details on using hashes here.

Supported by

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