from django.shortcuts import render
from django.conf import settings
from django.core.files.storage import FileSystemStorage
def search(request):
if request.method == 'POST' and request.FILES['myimage']:
results_arr = []
imagefile = request.FILES['myimage']
fs = FileSystemStorage()
filename = fs.save(imagefile.name, imagefile)
file_url = fs.url(filename)
return render(request, 'templateToRender.html', { 'filepath': file_url }) # in case you want to show the user the URL of the upload.
烧瓶碎片中的路径将放在
urls.py
中,其中有一个条目,如下所示在
^{pr2}$views.py
中,您将有一个函数,该函数如下所示,假设相应的HTML表单具有enctypemultipart/form-data
,并且HTML是一个文件上传。在假设您在设置中设置了
MEDIA_URL
和MEDIA_ROOT
,相应的函数可以转换为:您也可以使用
forms.py
在他们的文档here中提供了一个示例相关问题
PyPI热门下载资源包