python - 在django和python中上传文件?

标签 python django

    <input type="file" name="doc-file" multiple/>

   file_path = request.FILES.get('doc-file')

我的file_path的返回值为None

但是当我执行 file_path = request.POST.get('doc-file') 时,它会返回 filename 。在 python 和 django 中上传文件的最佳方式是什么?

最佳答案

听起来您可能忘记在表单标记中包含 enctype="multipart/form-data"。请参阅Django's docs on file uploads了解详情。

编辑:格式

关于python - 在django和python中上传文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4483020/

相关文章:

android - 使用 Django 将推送通知发布到 C2DM (android)

python - 如何将 Tensorflow One Hot 编码与基于 keras 的神经网络结合使用?

python - 属性错误 : module 'pydot' has no attribute 'graph_from_dot_data' in spyder

python - 如何在静态文件夹中使用 Flask 中的 opencv 显示新保存的图像?

python - 如何在 Python C API 中实现多态性?

python - Pandas 过滤数据框的正值和负值

mysql - 在django中从 "unqiue=True"更改为 "unique=False"

python - 他们如何在 Django 项目中的 python 控制台中运行这些命令?

django - 如何通过 Django 框架连接到 Google Cloud Postgresql?

Django:使用 cookie 保存和恢复表单的状态