Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attribute error 'WSGIRequest' object has no attribute 'Post' when using multiple submit buttons in my view

I am making a blog app and I need to give multiple buttons to the user when submitting his blog. I am checking which button is set and trying to do the action accordingly but it is not working properly.

Here is my views portion where I am checking which button is set in the POST data but when I click publish it works fine, but if I click save or publish then i get the error Attribute error 'WSGIRequest' object has no 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)
like image 928
Sachin Avatar asked Dec 16 '22 06:12

Sachin


1 Answers

The exception is telling you everything you need to know - there is no attribute "Post" on request. However, there is request.POST

like image 185
Brandon Avatar answered May 12 '23 03:05

Brandon