wagtail pages vs using django views and urls
Asked Answered
D

1

6

When and where should I use wagtail pages and when should I write my custom urls and views using django? for example should I create pages for user profiles or should I add a urlpattern for profile and write profile logic in a django view?

Denten answered 23/11, 2017 at 9:57 Comment(0)
W
7

This question is pretty broad and it depends a lot on what you are trying to achieve, but here are some thoughts.

General Approach

Use Wagtail pages if your pages have CMS (user) editable content and need to be placed (and easily moved) within the main page tree along with other editable pages.

If a page is not editable and URL must be fixed, it might be best to approach this either with Django URLs and views. Eg. Sitemap or Search page.

The docs cover how to set up mixed URLs in Integrating into Django.

Specific Use Case - User Profiles

You could create a Wagtail page model like UserProfileIndex which could contain some CMS editable content about that page such as body text and images.

This assumes you are wanting to make a social media type index and page for each user.

Then use RoutablePageMixin to have the URLs for each individual profile page.

Sometimes this index page thinking can come in handy, it let's you change the root URL but puts the logic for sub-urls within the model.

Remember that this means CMS users could technically change the slug of this page, unless it is locked down.

If you are trying to create a user profile page that is more suited for a user to manage their profile then it would probably best to use Django view.

Warfore answered 23/11, 2017 at 10:38 Comment(2)
Thank you @LB Ben Johnston for answering the question. Actually I agree that the question is broad, but I also look for general answers about it, something like best practices or rules of thumbs would be enough.Denten
Your point about editable content is a valuable approach to consider. And I'm also going to read more about the RoutablePageMixin. thanks againDenten

© 2022 - 2024 — McMap. All rights reserved.