我在項目中實現了django-ajax-uploader,但是我想要使用當前在3.5.0下的最新版本的fineuploader,作爲文檔說我應該做派csrf_token的唯一事情就是把它裏面customHeaders詞典:django-ajax-uploader如何用fine-uploader發送csrf_token 3.5.0
If you want to use the latest version of Fine Uploader, as valum's file-uploader is now called, instead of the one bundled with django-ajax-uploader, you can do so by replacing the params arguments in the above template with the following customHeaders:
customHeaders: { 'X-CSRFToken': '{{ csrf_token }}', },
這裏是我的全碼:
...
<h1>qq-file-uploader</h1>
<div id="upload-button" class="btn btn-primary"><i class="icon icon-cloud-upload icon-white"></i> Selecciona un archivo</div>
<div id="file-upload"></div>
</form>
{% endblock %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}js/libs/jquery.fineuploader-3.5.0/fineuploader-3.5.0.css"/>
{% endblock %}
{% block javascript %}
<script type="text/javascript" src="{{ STATIC_URL }}js/libs/jquery.fineuploader-3.5.0/jquery.fineuploader-3.5.0.min.js"></script>
<script type="text/javascript">
$(function(){
$('div#file-upload').fineUploader({
customHeaders: {
'X-CSRFToken': '{{ csrf_token }}'
},
request: {
endpoint: '{% url 'documents:qq_file_uploader' %}'
},
button: $('div#upload-button'),
multiple: false,
});
});
</script>
{% endblock %}
在我views.py
我:qq_file_uploader = AjaxFileUploader()
每次我嘗試上傳視圖中的任何文件時,我得到一個403錯誤:CSRF verification failed. Request aborted.
我做到了,現在正在工作,謝謝你幫助我,你是最好的 – 2013-05-02 14:53:17
「參數」是不正確的。這是Ray的答案中的「customHeaders」。 – Joel 2014-03-03 22:08:35