My django request.POST can't work.

def product_create_view(request, *args, **kwargs):

    form = ProductForm(request.POST or None)

    if form.is_valid() :      
        print(request.POST)
        print(form.cleaned_data)

  
    return render(request, 'forms.html', {'form':form})

My forms.html:

{% extends 'base.html' %}

{% block content %}

<form mathod="POST" action='.'>{% csrf_token %}

    {{ form.as_p }}

    <button type="submit"> Send data</button>

</form>

{% endblock %}

When I in my web enter something in textbox and send data.
My views.py
print(request.POST) show nothing and it can’t save to my admin product.

Please do not post screenshots of code here.

Copy/paste the code into the body of your message, between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```.

Sorry~
I will try again.

You’re close - it looks like you’re using apostrophe - ’ instead of the backtick - `

Anyway, from what I can see, the most likely case is that your form isn’t passing the is_valid test.

You can print your request.POST before the if to see what has been submitted.

It may also help to see your forms.html template. (Also posted as text here between lines of three backtick - ` characters.)

My forms.html:


{% block content %}

<form mathod="POST" action='.'>{% csrf_token %}

    {{ form.as_p }}

    <button type="submit"> Send data</button>

</form>

{% endblock %}

I know the method can change GET and POST ,
When I use ( mathod = ‘POST’ )
request.GET can get the data,
but request.Post can’t.

I see one issue - in your form tag in your template, the attribute should be method, not “mathod”.

1 Like

Oh… ,I found that mistake, thank for your helping~