我正在尝试在此documentation之后动态添加上传处理程序,但收到错误在处理完上传后,您无法更改上传处理程序。
这是我的views.py
# asset uploading view
# @login_required(login_url='login/')
@csrf_exempt
def upload_asset_view(request):
request.upload_handlers.insert(0, S3FileUploadHandler())
return _upload_asset_view(request)
@csrf_protect
def _upload_asset_view(request):
# form has been uploaded POST
if request.method == 'POST':
form = UploadAssetForm(request.POST, request.FILES)
if form.is_valid():
# store asset
asset = store_asset(form, request)
# print zip file details
# zip_data = print_zip_file_details('https://3d-configurator.s3.amazonaws.com/' + asset.file.name)
# textures = print_zip_file_details('http://roombuilder.s3.amazonaws.com/staging_bbby_google_ar/bbby_automation_backend/items/bbby-gltf-assets/133549_18660083_GLTF.zip')
# add message to sqs
# sqs_response = add_message_to_sqs(asset)
pprint('done')
# return render(request, 'dashboard/list_zip_data.html', {
# 'textures': textures,
# 'filename': asset.file.name
# })
else:
pprint('error')
pprint(form.errors)
# if GET, then get UploadAssetForm
else:
form = UploadAssetForm()
return render(request, 'dashboard/form_upload_asset.html', {
'form': form
})
这是我的模板
<form method="post" action="/" enctype="multipart/form-data">`
<p class="lead">Please upload your zip file</p>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
我使用了csrf_exempt
和csrf_protect
装饰器,但似乎仍无法找到错误。