【问题标题】:django uploadify 302 error with @user_passes_test decoratordjango 使用 @user_passes_test 装饰器上传 302 错误
【发布时间】:2023-03-17 00:49:01
【问题描述】:

您好,我在我的一个 django 应用程序中使用 Uploadify。它工作正常。但是当我使用 @user_passes_test 装饰器时,uploadify 得到一个 Http 302 错误。只有具有特定权限的登录用户才能使用文件上传。

我的观点是这样的:

@user_passes_test(lambda u: u.has_perm('cylebrations.can_multiupload'))
def myFileHandler(request):
    if request.method == 'POST':
        for field_name in request.FILES:
            image=Image(gallery_id=gallery.id, image=request.FILES[field_name])
            image.save()
            return HttpResponse("ok", mimetype="text/plain")
    return render_to_response('gallery_upload.html', context_instance=RequestContext(request))

当我在视图中使用以下内容而不是装饰器时,我也会收到 302 错误。

if not request.user.has_perm('cylebrations.can_multiupload'):
    return HttpResponse("You can't upload.")

看起来视图没有获取用户信息。 有没有办法通过uploadifys postData设置传递必要的用户信息?如何使用带有 django 权限的 uploadify?

【问题讨论】:

  • 请澄清一下,用户应该通过什么样的测试?我猜只有登录用户才能使用您的uploadify脚本?
  • 你说得对,只有登录的用户才能使用它。我编辑了问题。
  • @login_required 装饰器是否工作?
  • 不,@login_required 也不起作用。

标签: django uploadify


【解决方案1】:

这是一个论坛条目,展示了它是如何完成的: http://www.uploadify.com/forum/#/discussion/7195/uploadify-3-0-beta-with-django/p1

它包含一个指向another stackoverflow question 的链接,这也可能会有所帮助。

【讨论】:

  • 我创建了一个中间件并将 formData 添加到我的上传选项中。但我仍然收到 Http404 错误。
  • 我编辑了我的答案,因为我找到了一些链接。他们的做法与我提议的基本相同,但似乎他们已经测试了他们的解决方案
猜你喜欢
  • 2013-07-24
  • 1970-01-01
  • 2012-08-06
  • 2010-11-14
  • 1970-01-01
  • 2015-06-23
  • 2012-05-16
  • 1970-01-01
相关资源
最近更新 更多