English 中文(简体)
Django的立案卷,使用重载重荷,使吉大港山区应急反应法403
原标题:Upload files in Django using Uploadify getting HTTP response code 403

我正试图用

我的模板包括:

<script type="text/javascript" src="{{ STATIC_URL }}uploadify/swfobject.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}uploadify/jquery.uploadify.v2.1.4.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $( #file_upload ).uploadify({
             uploader   :  {{ STATIC_URL }}uploadify/uploadify.swf ,
             script     :  {% url upload_file %} ,
             cancelImg  :  {{ STATIC_URL }}uploadify/cancel.png ,
             auto       : true,
             multi      : true,
             fileExt    :  *.doc;*.docx;*.pdf ,
             fileDesc   :  Upload Docs ,
             queueID    :  file_upload_queue ,
             removeCompleted : false,
        });
    });
</script>

<h2 id="smallHeading"> Upload your Documents </h2>
<input id="file_upload" type="file" name="Filedata" />
<a href="javascript:$( #file_upload ).uploadifyUpload();">Upload Files</a>

My url.py文件载有这条线。

  url(r ^upload/$ ,  userprofile.views.upload_file , name= upload_file ), 

和观点

@csrf_exempt
def upload_file(request):
    if request.method == "POST":
        upload_file = request.FILES[ Filedata ]
        upload_instance = Uploads.objects.create(creator = request.user, uploaded_on = datetime.datetime.now())
    upload_instance.file.save(upload_file.name,upload_file)
    upload_instance.save()

    response = HttpResponse()
    response.write("%s
" % upload.name)
    return response

页: 1 目录

def get_file_path(instance, filename):
    return os.path.join( userprofiles , str(instance.creator.id), filename)

class Uploads(models.Model):
    file = models.FileField(upload_to=get_file_path)
    creator = models.ForeignKey(User)
    uploaded_on = models.DateTimeField()

但这里没有发生任何事情。 我得到的是上载纽,我选择了档案,但没有发生。 谁能帮助我了解正在发生什么? 看来没有发射<条码>。 我知道这一点,因为我以前的看法有误,但没有任何错误。

任何帮助都受到高度赞赏。

<><>Edit>:

我看不见<条码>射线/条码>和<条码><>>>。 小组还没有显示任何<代码>POST要求,但<代码>django debugger<>代码>显示POST要求以403的回复存档。 我使用了csrf_exempt。 那么,它为什么应当成为forbidden?

<>Solution: 我终于解决这个问题。 关于403个错误,我从 链接中发现了一些有趣之处。 如果一种观点有腐蚀器csrf_exempt,如果该观点有404个错误,那么django就显示出403个错误。

实际问题是,最初我的联系是错误的,因此,当我纠正这一联系时,我停止了403个错误,但我开始犯500个错误。 也就是说,有人认为有些错误。 而且,由于上载制在火焰中没有任何标志,我认为,我不得不通过上下线进行 de击。

看来由<编码>上载发送的申请标本。 文字不完整,而“条码>creator = 要求.user在制造物体时给我留下错误。 除此行外,上述法典完全可行。

问题回答

我建议进一步细化这一问题,看看问题是否在于客户的 Java印或服务器的Django代码。

Download the Firebug plugin for Firefox. Load your page. Open Firebug and go to the "Net" tab. Make sure that all the JavaScripts are loaded. Next, check the console to see if any JavaScript bugs are present. The next check the Django logs to see if any HTTP requests are coming through and perhaps have errors in them.

这将有助于你获得更多的信息,这将有助于你解决你的问题。 你总是能够用从上述步骤中收集的额外信息来更新你的问题。





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签