Skip to main content

A simple, Wagtail CMS inspired content block engine for Django. Intended to give slightly more control than regular flatpages.

Project description

django-page-blocks

django-page-blocks is intended to be a lightweight page content engine that can be integrated into an existing application to give site admins a little more control over page building. It's inspired by the block system in Wagtail CMS but isn't itself intended to be a full CMS, rather an enhanced version of the built in flatpages module.

This documentation is a bit brief at the moment but hopefully the info below can help you get set up.

It was developed and tested on Python 3.9 with Django 3.2. It will probably work on other recent versions of both as it doesn't do anything particularly special, but your mileage may vary.

The code is still under active development and is very much in an alpha state (hence the lack of documentation. As always, pull requests and feedback welcome.

Getting Started

Add the app to your INSTALLED_APPS

INSTALLED_APPS = [
  ...
  'pageblocks'
  ...
]

You can then either use the base model pageblocks.Page or extend it.

Admin

To allow proper editing of your pages, django-page-blocks provides an admin base class you can use against either your models, or the default one .. e.g.

from pageblocks.admin import PageAdmin

admin.site.register(Page, PageAdmin)

Serving Pages

You can serve pages by extending the PageView class. Your exact needs may differ, but here's a step by step example to look up and display a page based on it's slug field.

  1. Create a view extending the PageView class, defining either a queryset attribute or a get_queryset function to return a queryset of your page records for filtering. By default the view will select an object based on the slug url parameter if it's provided, but you can change this by overriding the get_object function:
from pageblocks.views import PageView
from myapp.models import Page

class MyPageView(PageView):
  template_name = 'page.html'
  queryset = Page.objects.all()
  1. Create a template (in the above example it should be page.html) that loads the pageblocks template tag:
{% load pageblocks %}

The current page will be available in the template as the page object and you can now render your page content with {% pageblocks page %}.

Of course you can mix and match this to meet your needs. If you need something more low level, you can render an individual list of blocks with the blocks tag .. e.g. {% blocks blocks %}

  1. Add it to your urlpatterns:
urlpatterns = [
  ...
  path('<slug:slug>/', MyPageView.as_view())
  ...
]

MultiLanguageField

By default, Page.title is a MultiLanguageField, which simply stores a dictionary with values for each language defined in settings.LANGUAGES. You can render this or any other MultiLanguageField in a template by using the multilang tag, e.g. {% multilang page.title %}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-page-blocks-0.1.1.tar.gz (17.3 kB view details)

Uploaded Source

File details

Details for the file django-page-blocks-0.1.1.tar.gz.

File metadata

  • Download URL: django-page-blocks-0.1.1.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for django-page-blocks-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f508e4c2d915312da7e15beb4f00830acea500043480cdc745e5316311e53c4a
MD5 43034157086def4bda19b5bec11e279a
BLAKE2b-256 f6b49f43140a877a6c8fe4839c298b1f91cfa8e5d68c9c9e24e5ba2326e2b668

See more details on using hashes here.

Supported by

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