如何在django view.py文件中获得通过html表单上传的文件的完整路径?

l0oc07j2  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(222)

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上。

js4nwp54

js4nwp541#

您需要在模型文件中设置上载路径。然后可以将其保存到视图函数中的特定路径。
详情请参阅-https://simpleisbetterthancomplex.com/tutorial/2016/08/01/how-to-upload-files-with-django.html

相关问题