Error attribute "WSGIRequest Object" does not have the "Message" attribute when using multiple submit buttons in my view

I am creating a blog application and I need to provide a few buttons to the user when submitting his blog. I check which button is installed and trying to perform an action, but it does not work properly.

Here is a part of my views where I check which button is installed in the POST data, but when I click publish, it works fine, but if I click the Save or Publish button, I get an error Attribute error The object WSGIRequest does not have attribute '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) 
+4
source share
1 answer

The exception tells you everything you need to know - there’s no Publish attribute on request. However, there is a .POST request

+12
source

Source: https://habr.com/ru/post/1385190/


All Articles