问题
I have an existing website that is a Django App.
I have installed Wagtail, and the Wagtail CMS is now accessible at www.example.com/cms
. Wagtail is working correctly with my database, and all the existing users are visible when I go to settings
and then users
, in the wagtail CMS admin page.
I want to use Wagtail to add blog functionality to my website.
Requirements
- I want any user to be able to create a new blog and add posts to their blog.
- I want the blog created by a user to be visible at
www.example.com/blogs/username/
How can I set Wagtail up to accomplish this?
I have checked the documentation at http://docs.wagtail.io/en/v1.9/ but could not figure out where to start with my modifications. I have also installed the example blog project (https://github.com/wagtail/wagtaildemo) but I was also unable to figure out how to accomplish 1 and 2 above from this.
Any complete answers, or general pointers, very welcome.
回答1:
The permission model built into Wagtail supports this kind of setup: http://docs.wagtail.io/en/stable/topics/permissions.html
After creating the index page for a blog, you'd create a group (Settings -> Groups in the Wagtail admin) for that blog - possibly just containing a single user - and under the 'Page permissions' section, assign it 'add' and 'publish' permission on that index page. Permissions propagate down the tree from that point, and 'add' permission encompasses the ability to edit pages that you've created yourself, so this would have the effect of giving the user control over the subpages of their blog.
This doesn't quite match the setup you've described, since it involves an existing Wagtail admin user having to do the initial setup, rather than users creating their own blog. However, since all of this configuration is done internally by creating / updating standard Django models such as Group
and PagePermission
, it would be possible in principle to script this process - for example, you could implement a Django view for "Set up my blog" on your site front-end, which runs the following steps:
- Create a BlogIndexPage under
/blogs
with a title/slug matchingrequest.user.username
(see https://stackoverflow.com/a/43041179/1853523 for how to create pages programmatically) - Create a user group (
django.contrib.auth.models.Group
) for the current user, and assign themwagtailadmin.access_admin
permission (so that they can log in to Wagtail admin) - Create a
wagtailcore.PagePermission
object corresponding to the newly-created group and blog index page, and 'add' permission; and likewise for 'publish' permission
来源:https://stackoverflow.com/questions/43095869/how-to-modify-wagtail-cms-so-that-any-user-can-post-blog-posts-under-their-own-b