gpt4 book ai didi

django - 在我的 View 中使用多个提交按钮时,属性错误 'WSGIRequest' 对象没有属性 'Post'

转载 作者:行者123 更新时间:2023-12-04 22:24:06 29 4
gpt4 key购买 nike

我正在制作一个博客应用程序,我需要在提交他的博客时为用户提供多个按钮。我正在检查设置了哪个按钮并尝试相应地执行操作,但它无法正常工作。

这是我的 View 部分,我正在检查 POST 数据中设置了哪个按钮,但是当我单击发布时它工作正常,但是如果我单击保存或发布,则会出现错误
属性错误 'WSGIRequest' 对象没有属性 'Post'

@login_required
def blog_form(request,author_id=None,slug=None):

context_instance=RequestContext(request)

# This view will have a valid creator_id and slug field if the
# blog is being edited and in this case the creator and user should be same
if ( author_id and slug):
author = User.objects.get(pk=author_id)
blog = get_object_or_404(Entry, creator = author, slug = slug)
if blog.creator != request.user:
raise HttpResponseForbidden()

# We set the user and created date and make a new object
else:
blog = Entry(creator=request.user,created_date=datetime.datetime.now() )

if request.method == 'POST':

#if the blog is not published
if 'save' in request.POST:
form = EntryForm(request.Post, instance = blog)
if form.is_valid():
form.save()

elif 'publish' in request.POST:
blog.pub_date = datetime.datetime.now()
blog.status = 1
form = EntryForm(request.POST, instance = blog)
if form.is_valid():
form.save()
return render_to_response('blog/blog_view.html', {'blog': blog,},context_instance=RequestContext(request))

elif 'preview' in request.POST:
form = EntryForm(request.Post, instance = blog)
if form.is_valid():
form.save()
return render_to_response('blog/blog_view.html', {'blog': blog,},context_instance=RequestContext(request))

else:
form = EntryForm(instance = blog)

return render_to_response('blog/blog.html', {'form':form}, context_instance)

最佳答案

异常(exception)是告诉您您需要知道的一切 - 请求时没有“发布”属性。但是,有 request.POST

关于django - 在我的 View 中使用多个提交按钮时,属性错误 'WSGIRequest' 对象没有属性 'Post',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8421592/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com