html:
<label for="image">Image</label>
Select a file: <input type="file" name="img">
Python:
image = (request.FILES.get("img"))
When I print image
it prints none
. If I just use {{form}}
in between the <form> </form>
tags it does send the image across to the view. However, for some specific reason I do not want to use the {{form}}
method.
Any ideas how I can approach this problem? Thanks in advance!
Make sure your <form>
has enctype="multipart/form-data"
, so it should look something like:
<form method="post" action="{URL}" enctype="multipart/form-data">
<input ...>
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.