我的django项目中的文件上传有问题.所以问题是:如何通过jquery ajax将文件传递给django视图?
这一刻我有
脚本:
<script type='text/javascript'>
$(document).ready(function() {
var csrf_token = $('input[name="csrfmiddlewaretoken"]').val();
$('#upload').click(function() {
$.ajax({
csrfmiddlewaretoken: csrf_token,
type: 'POST',
url : '../ajax/upload_file/',
enctype: "multipart/form-data",
data : {
'file': $('#file').val()
},
success: function(data) {
console.log(data)
}
})
})
})
</script>
Run Code Online (Sandbox Code Playgroud)
模板:
<form method="" action="" name='upload_form' id='upload_form' >{% csrf_token %}
<input type='file' name='file' id='file' />
<input type='button' value='Upload' id='upload'/>
</form>
Run Code Online (Sandbox Code Playgroud)
并查看:
@csrf_exempt
@xhr_to_json
def verifyFile(request):
if request.is_ajax():
file = request.FILES['file']
return {'message': file}
else:
return HttpResponseForbidden()
Run Code Online (Sandbox Code Playgroud)
现在我得到了
Traceback (most recent call …Run Code Online (Sandbox Code Playgroud) 如何在INSTALLED_APPS中的settings.py中导入所有模型?当我试图插入一些模型时,发生了一个错误:"没有名为app1_model的模型"
-ProjectName
--ProjectName
---models
----__init__.py
----admin.py
----app_1_model
----....
----app_n_model
---templates
---__init__.py
---settings.py
---urls.py
---wsgi.py
--manage.py
Run Code Online (Sandbox Code Playgroud)
^项目的结构^
我正在尝试编写一个脚本,它将删除Cassandra中的旧键空间.但我坚持如何定义何时创建某个键空间,即使有可能也不确定,我试图谷歌它,但遗憾的是没有发现任何东西.