每当我在django中调用uploaded_file_url时,它都会显示
但我手动检查。目录和文件存在
这是我的代码
uploaded_file_url=None
uploaded_file_url2=None
def upload(request):
if request.method == 'POST':
#request.FILES['myfile'] and request.FILES["myfile1"]:
myfile=request.FILES['myfile']
myfile2=request.FILES["myfile2"]
fs = FileSystemStorage()
filename = fs.save(myfile.name, myfile)
filename2=fs.save(myfile2.name, myfile2)
global uploaded_file_url
uploaded_file_url = fs.url(filename)
global uploaded_file_url2
uploaded_file_url2 = fs.url(filename2)
return HttpResponseRedirect('/home/')
#upload_file = request.FILES['upload_file']
#data = [row for row in csv.reader(upload_file.read().splitlines())]
return render(request, 'myapp/upload.html')
def home(request):
data= open(os.path.join(settings.MEDIA_ROOT, str(uploaded_file_url)),'rb').read()
//some code here
return render(request,'myapp/home.html',{"a":a})
设置配置
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
这里我要打开uploaded_file。这里有任何建议。谢谢提前