Issue
I want to create dynamic pages in Django like in WordPress but I am running out of clue. I have created django blog where data will be updated from admin site and dynamic blog pages will be generated based on postlist, postdetail, and sidebar widget.
Now,
I want to create page where from single view multiple page can be created. For example, About Us page, About Services Page, Contact page, Some Static Page (like privacy policy..)
Where admin will be able to update the content from admin side and decide which content to display on which part of that page. Like ( Image, Video, texts, slides, etc, but that will be independent of template configuration) Like WordPress page customization.
Solution
With regards to the use-case of About Us/Contact/Policy type pages, i.e pages which change infrequently, Django has the flatpages app. Documentation here:
https://docs.djangoproject.com/en/3.2/ref/contrib/flatpages/
Flatpages plugs nicely into admin, so you can update them from there.
It also sounds like you want a WYSIWYG editor. For this I would recommend CKEditor. Its highly customisable and there is a well maintained and popular Django integration for it https://pypi.org/project/django-ckeditor/
Its also possible to get CKEditor to work with your flatpages:
admin.py
from ckeditor.widgets import CKEditorWidget
from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
class FlatPageAdmin(FlatPageAdmin):
formfield_overrides = {models.TextField: {"widget": CKEditorWidget}}
# workaround to get the flatpages app to use CKeditor
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)
Answered By - PJ Simpo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.