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

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

home.html

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

views.py

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

我想要文件路径,这样我就可以使用graphapi将文件上传到facebook上。

js4nwp54

js4nwp541#

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

相关问题