Django + SWFUpload的代码示例? [英] Code samples for Django + SWFUpload?
问题描述
不幸的是,我不能给你任何详细的代码示例,但是我使用SWFUpload + Django(对于我工作的照片共享站点)有相当多的经验。无论如何,这里有几个指针,希望能够帮助您对DjSWF幸福的追求:)
-
你会想使用cookies插件(如果您当然使用某种基于会话的身份验证[像
django.contrib.auth
,关心谁上传了什么)。
Cookie插件将Cookie中的数据作为POST发送,因此您必须找到一些方法将其重新导入
request.COOKIES
(process_request
中间件在request.POST 中查找
settings.SESSION_COOKIE_NAME
code>在特定的URL,并将其转储到request.COOKIES
非常适合这样做:) - 另外,请记住,您必须在响应正文中返回一些SWFUpload,以将其识别为成功的上传尝试。我相信SWFUpload的最新测试版已经发生了变化,但无论如何,只要坚持像ok一样的东西就行了。对于失败,请使用像
HttpResponseBadRequest
等类似的东西。 -
最后,上传的文件位于
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 :)
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 asettings.SESSION_COOKIE_NAME
inrequest.POST
on specific URLs and dumps it intorequest.COOKIES
works nicely for this :)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.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屋!