how to upload file with pjango

47 views
Skip to first unread message

meInvent bbird

unread,
May 27, 2016, 5:45:28 AM5/27/16
to Django users
how to upload file with pjango ?

Ricardo Daniel Quiroga

unread,
May 27, 2016, 9:50:29 AM5/27/16
to django...@googlegroups.com
Hello,

add enctype="multipart/form-data" param in you html form

see more info




2016-05-27 6:45 GMT-03:00 meInvent bbird <jobma...@gmail.com>:
how to upload file with pjango ?

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f68770a9-58ae-4cf3-9893-c8793b192fa1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Ricardo Daniel Quiroga

meInvent bbird

unread,
May 31, 2016, 9:53:16 PM5/31/16
to Django users
after following the web,

it only run one time first time the function in views.py
but after press button, it do not run post method because console did not show POST.

where is wrong?

Ricardo Daniel Quiroga

unread,
Jun 1, 2016, 9:14:14 AM6/1/16
to django...@googlegroups.com
I suggest redefining the form

class UploadFileForm(forms.Form):
    title = forms.CharField(max_length=50)
    file2 = forms.FileField()
    MAX_FILE_SIZE = forms.CharField(widget=forms.HiddenInput(), initial = 10000) 
    

and in template upload.html you tried this?

<form action="#" enctype="multipart/form-data" method="POST">
    <label> Title </label> {{ form.title }} <br>
    <label>Choose a file to upload:</label> {{ form.file2 }} <br>
    {{ form.MAX_FILE_SIZE }} <!-- hidden -->
    <input type="submit" value="Upload File"/>
</form>





For more options, visit https://groups.google.com/d/optout.



--

Ricardo Daniel Quiroga

meInvent bbird

unread,
Jun 1, 2016, 10:21:57 PM6/1/16
to Django users
wonderful, this code succeed to run
Reply all
Reply to author
Forward
0 new messages