Forms questions

57 views
Skip to first unread message

Hugo Kitano

unread,
Aug 24, 2015, 5:16:40 PM8/24/15
to Django users
Hi, I'm trying to figure out what's wrong with my form:

I've noticed that every time I load my submit view, the request.method is GET not POST, so nothing gets saved to the database.


Here's views.py


models.py


Thanks!!

Auto Generated Inline Image 1
Auto Generated Inline Image 2

Sait Maraşlıoğlu

unread,
Aug 24, 2015, 7:31:47 PM8/24/15
to Django users
Can you provide the template code?

Hugo Kitano

unread,
Aug 25, 2015, 1:10:30 PM8/25/15
to Django users
Here it is, very simple:

<h1> Submit form: </h1>
<form action="/stats/" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <p><input type="submit" value="Submit" /></p>
</form>

Hugo Kitano

unread,
Aug 25, 2015, 3:12:46 PM8/25/15
to Django users
I've realized that the action field in the form should be "/stats/submit/", the same view as the one that sent me to the template.  However, whenever I submit with the form then, it tells me that the file I submit is missing, even when it is definitely there.

Martin Torre Castro

unread,
Sep 19, 2015, 4:26:46 AM9/19/15
to Django users
If there's a file in the form data, I'm no expert but I have fought a little with forms and files and I advise you to look in the internet for multipart forms and file inputs inside forms.

Tom Evans

unread,
Sep 22, 2015, 7:28:58 AM9/22/15
to django...@googlegroups.com
On Tue, Aug 25, 2015 at 6:10 PM, Hugo Kitano <hkit...@gmail.com> wrote:
>
> Here it is, very simple:
>
> <h1> Submit form: </h1>
> <form action="/stats/" method="post">
> {% csrf_token %}
> {{ form.as_p }}
> <p><input type="submit" value="Submit" /></p>
> </form>
>

Read this section of the manual, particularly the section starting
"Firstly, ...". The problems yo uare having are that you aren't
telling Django there are files to read in the POST, and even if the
files were being read from the POST, you aren't passing them to the
form.

https://docs.djangoproject.com/en/1.8/ref/forms/api/#binding-uploaded-files-to-a-form

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages