简体   繁体   中英

request.FILES empty uploading image on Django

Here is my HTML sending the request, printing request.FILES return <MultiValueDict: {}> . Also i would ask how can i save my charged picture (is ok to only form.save() ?)

<form action="send_news" method="POST" encrypt="multipart/form-data">
    {% csrf_token %} {{ form.as_p }}
    <p>
        <label for="news_title">Your name: </label>
        <input id="news_title" type="text" name="news_title" value="newtitle">
    </p>
    <p>
        <label for="news_small_description">Your name: </label>
        <input name="news_small_description" id="news_small_description" value="news_small_description">
    </p>
    <p>
        <label for="news_description">Your name: </label>
        <input name="news_description" id="news_description" value="news_description">
    </p>

    <p>
        <label for="news_image">Your name: </label>
        <input id="news_image" type="file" class="" name="news_image">
    </p>

    <input type="submit" value="Submit" />
</form>

printing request.FILES return <MultiValueDict: {}> . Also i would ask how can i save my charged picture (is ok to only form.save() ?)

The problem is you are using encrypt but you need to use enctype

eg

<form action="send_news" method="POST" enctype="multipart/form-data">

See What does enctype='multipart/form-data' mean? for more info if needed.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM