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

Uploaded Source

Built Distribution

canonicalwebteam.blog-2.4.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: canonicalwebteam.blog-2.4.1.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/5.0.0-25-generic

File hashes

Hashes for canonicalwebteam.blog-2.4.1.tar.gz
Algorithm Hash digest
SHA256 86251550ffea06c0738ffc70a29044e8354de1c69f4977c206af33c5783842cd
MD5 e56a617bfe88cb7d9348e3d0e0d72107
BLAKE2b-256 06fc9f3b9791823d63db4298f9fe1a8afa383bbda9275dd2f6b1f86040220e63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canonicalwebteam.blog-2.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7f9c67f80d8118de86cfb43cb10d9ef194d51959e61f07489f1d904dc9fe893
MD5 c396841e8298b7a0e1087afa5c935d1c
BLAKE2b-256 a523e280d140ed39c9f2746882fd94b8ef786ea673a5961601940d20799a26ea

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