Django + SWFUpload的代码示例? [英] Code samples for Django + SWFUpload?

查看:102
本文介绍了Django + SWFUpload的代码示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有任何简单的代码示例Django + SWFUpload ?我在PHP应用程序中工作得很好,但Django让我头痛。

解决方案

不幸的是,我不能给你任何详细的代码示例,但是我使用SWFUpload + Django(对于我工作的照片共享站点)有相当多的经验。无论如何,这里有几个指针,希望能够帮助您对DjSWF幸福的追求:)


  1. 你会想使用cookies插件(如果您当然使用某种基于会话的身份验证[像 django.contrib.auth ,关心谁上传了什么)。



    Cookie插件将Cookie中的数据作为POST发送,因此您必须找到一些方法将其重新导入 request.COOKIES process_request 中间件在 request.POST 中查找 settings.SESSION_COOKIE_NAME code>在特定的URL,并将其转储到 request.COOKIES 非常适合这样做:)


  2. 另外,请记住,您必须在响应正文中返回一些SWFUpload,以将其识别为成功的上传尝试。我相信SWFUpload的最新测试版已经发生了变化,但无论如何,只要坚持像ok一样的东西就行了。对于失败,请使用像 HttpResponseBadRequest 等类似的东西。


  3. 最后,上传的文件位于 request.FILES 中:)


如果您有任何令人困惑的事情,我没有涵盖,请随时发布更详细的内容,我将很乐意为您提供帮助。


Does anyone have any simple code samples for Django + SWFUpload? I have it working perfectly in my PHP application but Django is giving me headaches.

解决方案

Unfortunately I can't give you any very detailed code samples, but I have quite a bit of experience with working with SWFUpload + Django (for a photo sharing site I work on). Anyway, here are a few pointers that will hopefully help you on your quest for DjSWF happiness :)

  1. You'll want to use the cookies plugin (if of course you are using some sort of session-based authentication [like django.contrib.auth, and care who uploaded what).

    The cookies plugin sends the data from cookies as POST, so you'll have to find some way of getting this back into request.COOKIES (process_request middleware that looks for a settings.SESSION_COOKIE_NAME in request.POST on specific URLs and dumps it into request.COOKIES works nicely for this :)

  2. Also, remember that you must return something in the response body for SWFUpload to recognize it as a successful upload attempt. I believe this has changed in the latest beta of SWFUpload, but anyway it's advisable just to stick something in there like 'ok'. For failures, make use of something like HttpResponseBadRequest or the like.

  3. Lastly, in case you're having trouble finding them, the uploaded file is in request.FILES :)

If you have anything perplexing I haven't covered, feel free to post something more detailed and I'll be happy to help.

这篇关于Django + SWFUpload的代码示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆