问题描述
我仍在努力将django wagtail集成到现有项目中。
i'm still struggling to integrate django wagtail to an existing project.
我在我的博客页面上只使用wagtail。并且我想创建一个表格,以便从我的w页面上为我的博客创建新帖子。我创建此方法的方法是使用routablepage。这是我的一些代码
i'm only using wagtail for my blog page. and i want to create a form to create new post for my blog from my wagtail page. the way i create this is using an routablepage. here's some of my code
我正在使用作为我的参考
i'm using this as my reference
models.py
models.py
class BlogIndex(RoutablePageMixin, Page):
...
@route(r'^send-post/$', name='send_posts')
def submit(self, request):
from .views import submit_news
return submit_news(request, self)
...
class BlogPage(Page):
...
form.py
class NewsPageForm(forms.ModelForm):
...
views.py
def submit_blog(request, blog_index):
...
是否可以将Submit_blog函数更改为创建视图?
,因为我之前曾尝试过创建视图并尝试类似的操作,但是它不起作用,因为它将在模型中调用xp的BlogPage页面。py
is it possible to change submit_blog function into create view ?because i've tried to make create view before and try something like this but it doesn't work because it will recursive to call the BlogPage Page in models.py
models.py
models.py
class BlogIndex(RoutablePageMixin, Page):
...
@route(r'^send-post/$', BlogCreate.as_view(), name='send_posts')
views.py
class BlogCreate(CreateView):
...
非常感谢
推荐答案
我认为您已经快到了,但是 @route
需要装饰视图函数(而不是将视图作为装饰器参数传递)。
I think you're nearly there, but @route
needs to decorate a view function (rather than passing the view as a decorator parameter).
尝试一下:
class BlogIndex(RoutablePageMixin, Page):
...
@route(r'^send-post/$', name='send_posts'):
def submit(self, request):
blog_create_view = BlogCreate.as_view()
return blog_create_view(request, self)
而不是:
class BlogIndex(RoutablePageMixin, Page):
...
@route(r'^send-post/$', BlogCreate.as_view(), name='send_posts')
这篇关于是否可以使用基于类的视图而不是基于函数的视图w?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!