Skip to main content

Flask extension and Django App to add a nice blog to your website

Project description

Blog flask extension

This extension allows you to add a simple blog frontend to your flask app. All the articles are pulled from the WordPress API that has the plugin WP-JSON.

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 use

Flask

In your app you can:

    import canonicalwebteam.blog_extension import BlogExtension
    blog = BlogExtension(app, "Blog title", [1], "tag_name", "/url-prefix")

If you use the factory pattern you can also:

    import canonicalwebteam.blog_extension import BlogExtension
    blog = BlogExtension()
    blog.init_app(app, "Blog title", [1], "tag_name", "/url-prefix")

Django

  • Add the blog module as a dependency to your Django project
  • Load it at the desired path (f.e. "/blog") in the urls.py file
from django.urls import path, include
urlpatterns = [path(r"blog/", include("canonicalwebteam.blog.django.urls"))]
  • In your Django project settings (settings.py) you have to specify the following parameters:
BLOG_CONFIG = {
    # the id for tags that should be fetched for this blog
    "TAGS_ID": [3184],
    # the title of the blog
    "BLOG_TITLE": "TITLE OF THE BLOG",
    # the tag name for generating a feed
    "TAG_NAME": "TAG NAME FOR GENERATING A FEED",
}
  • Run your project and verify that the blog is displaying at the path you specified (f.e. '/blog')

Groups pages

  • Group pages are optional and can be enabled by using the view canonicalwebteam.blog.django.views.group. The view takes the group slug to fetch data for and a template path to load the correct template from. Group pages can be filtered by category, by adding a category=CATEGORY_NAME query parameter to the URL (e.g. http://localhost:8080/blog/cloud-and-server?category=articles).
from canonicalwebteam.blog.django.views import group

urlpatterns = [
    url(r"blog", include("canonicalwebteam.blog.django.urls")),
    url(
        r"blog/cloud-and-server",
        group,
        {
            "slug": "cloud-and-server",
            "template_path": "blog/cloud-and-server.html"
        }
    )

Topic pages

  • Topic pages are optional as well and can be enabled by using the view canonicalwebteam.blog.django.views.topic. The view takes the topic slug to fetch data for and a template path to load the correct template from.

urls.py

path(
		r"blog/topics/kubernetes",
		topic,
		{"slug": "kubernetes", "template_path": "blog/kubernetes.html"},
		name="topic",
),

Templates

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: canonicalwebteam.blog-2.4.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.6.8 Linux/4.15.0-58-generic

File hashes

Hashes for canonicalwebteam.blog-2.4.0.tar.gz
Algorithm Hash digest
SHA256 6464c916b7cf2264a6012e4edabfe358589f827647c99d0144b5cc377c992552
MD5 f9a925ab9e1758599510c2747c696ce9
BLAKE2b-256 cf2255e4d8fc3ee0d62a668d43d9761c7d120ee5512f0d3969b1617372426d14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canonicalwebteam.blog-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4657691f1724c6c3b73f5c2e397413358b0200fdac7a0feca3578decbc8047f
MD5 88f86482f3735d279f04630804fe8348
BLAKE2b-256 b2e81f1914dd649a0f01615b6037e6180b5dbcf819a517582d5272656787bd07

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