【问题标题】:How to check request.FILES is black or not in Djnago?如何在 Django 中检查 request.FILES 是否为黑色?
【发布时间】:2020-09-16 08:39:26
【问题描述】:

我正在使用 Djnago.i 有如下 html 表单,

<form method="POST" action="{% url 'someaction' %}" enctype="multipart/form-data">
    <input type="file"  name="image" id="image">
</form>

如何检查request.FILES['image']在djnago视图文件中是否被选中?

【问题讨论】:

  • 检查request.FILES['image'] 的空虚就够了吗?

标签: django django-models django-views django-templates


【解决方案1】:

做:

image = request.FILES.get('image')
if image is None:
    # request.FILES['image'] is not posted

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多