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 ```.
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~