【问题标题】:How to get a full path of file uploaded via HTML form in django view.py file?如何在 django view.py 文件中获取通过 HTML 表单上传的文件的完整路径?
【发布时间】:2021-07-08 12:03:20
【问题描述】:

home.html

<form action="" method="POST" enctype="multipart/form-data">
        {% csrf_token %}
        <input type="file" name = 'img' >
        <button type="submit"> Post On Facebook </button>
</form>

views.py

def home(request):
    if request.method == 'POST':
          # get the image absolute location 
        
    return render(request,'home.html')

我想要文件路径,以便我可以使用 GraphAPI 将文件上传到 Facebook。

【问题讨论】:

标签: python django path


【解决方案1】:

您需要在模型文件中设置上传路径。 然后,您可以将其保存到视图函数中的特定路径。

详情请参考-https://simpleisbetterthancomplex.com/tutorial/2016/08/01/how-to-upload-files-with-django.html

【讨论】:

    猜你喜欢
    • 2013-04-27
    • 2014-06-08
    • 2011-08-14
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 2016-03-13
    • 2013-11-24
    • 2016-11-26
    相关资源
    最近更新 更多