In my django project, I am trying to create a form which the user will access through a specific url.
By clicking on the url, the user will be automatically redirected to a pager_id
.
Inbetween the user click on said url and being redirected to page_id
, a form will be passed in the background, without any template.
Slight problem, the form does not pass the if request.method == "POST":
.
I know that because the print rendered in the console is this is not a post request
.
I think its the probably the first time Im not using a template to render theform. I would normally specify something like:
<form "method="POST">
{% csrf_token %}
</form>
Question:
Assuming this what is causing problem: Does Django require to use a template to render the form? Or is there a way to specify method="POST"
in a different way? Or is there something else I am not seeing?
views.py
def function(request, page_id):
form = myform(request.POST)
if request.method == "POST":
print('this is a post request')
if form.is_valid():
data = form.save(commit=False)
...
data.save()
return redirect('page', page_id=page_id)
else:
form = myform()
print('this is not a post request') #<-- this is what gets printed in the console
else:
print('Come back later!')
return redirect('page', page_id=page_id)