[Answered ]-Django ~ WSGIRequest with a form added via get_context_data method

1👍

Probably you’re right and you were passing request instead of request.POST, reqest.GET or request.REQUEST to the constructor of your form. See the doc on how to use forms:

def contact(request):
    if request.method == 'POST': # If the form has been submitted...
        form = ContactForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            return HttpResponseRedirect('/thanks/') # Redirect after POST
    else:
        form = ContactForm() # An unbound form

    return render_to_response('contact.html', {
        'form': form,
    })

1👍

Two problems that I can see. The easy one being that you can simply replace this line:

context['form'] = createNewStoryForm(self.request)

with

context['form'] = StoryForm(request.POST, request.FILES)

Finally shouldn’t this:

class StoryShowView(ListView):
    model = StoryForm

Be:

class StoryShowView(ListView):
    model = Story

Leave a comment