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.
- 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()
- 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 %}. Custom blocks can also include stylesheet and script dependencies, which you can render in your template with {% pageblocks_scripts page %} and {% pageblocks_stylesheets page %} accordingly.
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 %}
- 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 %}
Custom Blocks
This package comes with a couple of built in blocks, but you'll probably quickly outgrow them and need to add your own. You can do this by extending the pageblocks.blocks.BaseBlock class.
This documentation needs fleshing out a bit, but for now, a good place to start would be to look at the source code for HTMLBlock which should hopefully give you an idea of how to extend it.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-page-blocks-0.3.3.tar.gz.
File metadata
- Download URL: django-page-blocks-0.3.3.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41ccf041b4e473c1f8e84d8faa1467e0649ef934f9261c802fb11ecb4082c224
|
|
| MD5 |
2ec529d65a6a439942a4080ae760672c
|
|
| BLAKE2b-256 |
eff8412ef924e300c261fc79d60d111e5f23e0fc1a7c4ff013dc318ec387c383
|
File details
Details for the file django_page_blocks-0.3.3-py3-none-any.whl.
File metadata
- Download URL: django_page_blocks-0.3.3-py3-none-any.whl
- Upload date:
- Size: 32.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed0fe320cf5c35d11ab8794c525ac62b9b87c2be10e42f8b3393cd421baebb02
|
|
| MD5 |
657fabb15e32a4f19db9c4929eab2bc1
|
|
| BLAKE2b-256 |
51bdffd90a1217b8f116f4da6922faba9acd47d1966ce02f8610e4ffdf03484e
|