Image browsing in django

82 views
Skip to first unread message

Harjot Mann

unread,
Oct 11, 2013, 1:52:03 AM10/11/13
to django...@googlegroups.com
When I am browsing an image in my form it is giving me this error even
after browsing the image. :(
http://screencloud.net/v/ch9e

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

Tom Evans

unread,
Oct 11, 2013, 6:14:28 AM10/11/13
to django...@googlegroups.com
On Fri, Oct 11, 2013 at 6:52 AM, Harjot Mann <harjotm...@gmail.com> wrote:
> When I am browsing an image in my form it is giving me this error even
> after browsing the image. :(
> http://screencloud.net/v/ch9e

Forms containing files must have encoding type of
"multipart/form-data" or the file will not be submitted with the rest
of the form.

http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean

Cheers

Tom

Harjot Mann

unread,
Oct 14, 2013, 9:25:33 AM10/14/13
to django...@googlegroups.com
On Fri, Oct 11, 2013 at 3:44 PM, Tom Evans <teva...@googlemail.com> wrote:
> Forms containing files must have encoding type of
> "multipart/form-data" or the file will not be submitted with the rest
> of the form.


Didn't get you here. My problem is this that when I am browsing for
image ita takes int he upload area but when I submit, it gives me an
error no files selected?

Tom Evans

unread,
Oct 14, 2013, 11:04:21 AM10/14/13
to django...@googlegroups.com
On Mon, Oct 14, 2013 at 2:25 PM, Harjot Mann <harjotm...@gmail.com> wrote:
> On Fri, Oct 11, 2013 at 3:44 PM, Tom Evans <teva...@googlemail.com> wrote:
>> Forms containing files must have encoding type of
>> "multipart/form-data" or the file will not be submitted with the rest
>> of the form.
>
>
> Didn't get you here. My problem is this that when I am browsing for
> image ita takes int he upload area but when I submit, it gives me an
> error no files selected?
>

Yes, this is what I said before. Forms that contain files must be
specified in the HTML differently than forms that do not contain
files, or when the form is submitted, the file will not be submitted
along with the form.

Forms with files must have an encoding attribute set on the <form>
element, eg "<form encoding='multipart/form-data' ....>". If they do
not, files will not be submitted when the form is submitted.

The stackoverflow page I linked to previously explains why in detail.

Cheers

Tom

Harjot Mann

unread,
Oct 14, 2013, 12:16:21 PM10/14/13
to django...@googlegroups.com
On Mon, Oct 14, 2013 at 8:34 PM, Tom Evans <teva...@googlemail.com> wrote:
> Yes, this is what I said before. Forms that contain files must be
> specified in the HTML differently than forms that do not contain
> files, or when the form is submitted, the file will not be submitted
> along with the form.
>
> Forms with files must have an encoding attribute set on the <form>
> element, eg "<form encoding='multipart/form-data' ....>". If they do
> not, files will not be submitted when the form is submitted.


Done..but again getting the same error. I am doing it like this:
This is my model:
image=models.ImageField(upload_to='images')

and then in my html form I am doing it like this:
<form action="" method="post" encoding='multipart/form-data'>
{% csrf_token %}
<table >
{{ form.as_table }}
</table>
<input type="submit" value="Submit">
</form>

Harjot Mann

unread,
Oct 14, 2013, 12:18:02 PM10/14/13
to django...@googlegroups.com
On Mon, Oct 14, 2013 at 9:46 PM, Harjot Mann <harjotm...@gmail.com> wrote:
> Done..but again getting the same error. I am doing it like this:
> This is my model:
> image=models.ImageField(upload_to='images')
>
> and then in my html form I am doing it like this:
> <form action="" method="post" encoding='multipart/form-data'>
> {% csrf_token %}
> <table >
> {{ form.as_table }}
> </table>
> <input type="submit" value="Submit">
> </form>


I have not done anything special in views..it just contains a simple
form saving code.
Should I need to do anything there?

Harjot Mann

unread,
Oct 16, 2013, 12:41:06 AM10/16/13
to django...@googlegroups.com
On Mon, Oct 14, 2013 at 9:48 PM, Harjot Mann <harjotm...@gmail.com> wrote:
> I have not done anything special in views..it just contains a simple
> form saving code.
> Should I need to do anything there?


Please reply. I am waiting :(

Sanjay Bhangar

unread,
Oct 16, 2013, 3:21:33 AM10/16/13
to django...@googlegroups.com
Harjot,

It is enctype='multipart/form-data' and not encoding='multipart/form-data'

Hope that helps - all the best,
Sanjay
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAB0GQhDC1MstEPp3LD_zgdAS0QMsoL3p-2pO3HhRvu6OPW14mQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Harjot Mann

unread,
Oct 16, 2013, 3:36:34 AM10/16/13
to django...@googlegroups.com
On Wed, Oct 16, 2013 at 12:51 PM, Sanjay Bhangar
<sanjay...@gmail.com> wrote:
> It is enctype='multipart/form-data' and not encoding='multipart/form-data'
>
> Hope that helps - all the best,
> Sanjay


No same problem,please help me...please help me...please help me..I
have posted this mail 5 days ago and no one is able to solve my
problem. :( I am really disappointed :(

Harjot Mann

unread,
Oct 16, 2013, 3:45:41 AM10/16/13
to django...@googlegroups.com
On Wed, Oct 16, 2013 at 1:06 PM, Harjot Mann <harjotm...@gmail.com> wrote:
>
> No same problem,please help me...please help me...please help me..I
> have posted this mail 5 days ago and no one is able to solve my
> problem. :( I am really disappointed :(


Please tell me the solution. I have to complete my work soon. please.

Mario Gudelj

unread,
Oct 16, 2013, 5:10:00 AM10/16/13
to django...@googlegroups.com

I reckon you're not passing request.FILES to your form class together with request.POST inside your view. Hopefully that's enough info. Typing from a phone.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Skyler Dawson

unread,
Oct 16, 2013, 9:36:58 AM10/16/13
to django...@googlegroups.com
Hi Harjot,

First, I noticed your form action is empty (""). Depending on your browser, this can mean different things (some browsers take it as an action that gets sent back to the index page), as described in this answer on stackoverflow: http://stackoverflow.com/questions/1131781/is-it-a-good-practice-to-use-an-empty-url-for-a-html-forms-action-attribute-a

Hopefully you're developing on a more recent browser so this isn't actually the issue, but it's still good to know about.

Second, when asking questions, it's best to give us as much information as possible, therefore posting your view that is supposed to actually handle the form might help us.

Finally, people are donating their time here generously to help you out; complaining that no one has an automatic solution is frankly quite silly. We don't have your code, you're asking us to remote debug with very little information. Debugging is a very important skill, and I don't see you posting what other attempts you've made to debug this issue. Anyway, tl;dr the internet is not your personal army, etc.
Reply all
Reply to author
Forward
0 new messages