Django - how to fix - request.POST.get returns None?

General Tech Bugs & Fixes 3 years ago

1.94K 1 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago

 

I'm learning django and trying to get the user's vote from a detailview. The user chooses from radio buttons and clicks on a submit button.

The detailview's template's form's action is set to a formview url.

Inside the urls I have require_POST on the formview.

Inside the template and a for loop:

<input type="radio" name="choice" value="{{one.name}}">
<label for="{{one.name}}">{{one.name}}label><br>

Inside a form view:

def form_valid(self, form):
    request = HttpRequest()
    vote = request.POST.get('choice')
    return HttpResponse(vote)

When I submit the form I can see the choice param in firefox network under post method but the view returns None.

What am I doing wrong?

0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum