代码:
company = Company.objects.get(pk=pk)
if request.POST:
company_name = request.POST['company_name']
company_logo = request.FILES['company_logo']
fs = FileSystemStorage(location='/home/ubuntu/mywebsite/media/company/' + str(company.pk) + '/')
filename = fs.save(company_logo.name, company_logo)
uploaded_file_url = fs.url(filename)
fs.url
返回:/media/thefilename.png
这是错误的......显然该.url
方法没有考虑到您将location
属性设置为什么?
如何确保返回正确的路径?