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.

How to install

To install this extension as a requirement in your project, you can use PIP;

pip install canonicalwebteam.blog

See also the documentation for (pip install)[https://pip.pypa.io/en/stable/reference/pip_install/].

How to use

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.

Flask

In your app you can then:

    import flask
    from canonicalwebteam.blog import BlogViews
    from canonicalwebteam.blog.flask import build_blueprint

    app = flask.Flask(__name__)

    # ...

    blog_views = BlogViews()
    app.register_blueprint(build_blueprint(blog_views), url_prefix="/blog")

You can customise the blog through the following optional arguments:

    blog_views = BlogViews(
        blog_title="Blog",
        tag_ids=[1, 12, 112],
        exclude_tags=[26, 34],
        feed_description="The Ubuntu Blog Feed",
        per_page=12, # OPTIONAL (defaults to 12)
    )
    app.register_blueprint(build_blueprint(blog_views), url_prefix="/blog")

Development

The blog extension leverages poetry for dependency management.

Regenerate setup.py

poetry install
poetry run poetry-setup

Testing

All tests can be run with poetry run pytest.

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 && poetry run pytest.

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-5.0.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

canonicalwebteam.blog-5.0.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: canonicalwebteam.blog-5.0.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for canonicalwebteam.blog-5.0.0.tar.gz
Algorithm Hash digest
SHA256 47db1e684653f554cbee64004c01d8fe8f33f22faf1b4a6498b4453f2f7e1a49
MD5 7deac43572589363310c8263a26c5fe3
BLAKE2b-256 de7433eb049a53c03b9756b4f952c8398d26a744b0d99bfa335f4acadb1953f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canonicalwebteam.blog-5.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for canonicalwebteam.blog-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 917d0c9388512a5a49b435d32360d4cc182e56c8bc712d27ff341132886e00d7
MD5 744ed63aaec98e08745d977f9ca65174
BLAKE2b-256 d8d287c7d267a603e99a05431b9945a1153ea356b6df1d0645cc4fdaf6cb8f79

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