代码之家  ›  专栏  ›  技术社区  ›  Mathias Nielsen

Django CNotes不工作

  •  0
  • Mathias Nielsen  · 技术社区  · 15 年前

    我刚安装好 django-cnotes 但它不起作用。 它只是抛出这个错误

    回溯(最近一次呼叫的最后一次):

    File "/Library/Python/2.5/site-packages/django/core/servers/basehttp.py", line 279, in run
    self.result = application(self.environ, self.start_response)
    
    File "/Library/Python/2.5/site-packages/django/core/servers/basehttp.py", line 651, in __call__
    return self.application(environ, start_response)
    
    File "/Library/Python/2.5/site-packages/django/core/handlers/wsgi.py", line 245, in __call__
    response = middleware_method(request, response)
    
    File "/Library/Python/2.5/site-packages/django_cnote-0.3.4-py2.5.egg/cnotes/middleware.py", line 47, in process_response
    signed_data = self.sign('cnotes', base64.urlsafe_b64encode(Pickle.dumps(cnotes.cnotes)))
    
    PicklingError: Can't pickle <class 'django.utils.functional.__proxy__'>: attribute lookup django.utils.functional.__proxy__ failed
    

    它甚至不在正常的Django错误调试页面中。你在上面看到的是屏幕上所有的东西。

    我刚刚用过Github上描述的,我就是不明白。有人知道这是什么原因吗?

    更新: 好吧,我想我找到了一些东西。

    message = _("You have successfully altered ")
    message += edituser.username
    cnotes.add(message)
    message2 = _("You may now close ")
    cnotes.add(message2)
    

    这将导致错误。所以我想,“好吧,我只能在每个视图中调用一次”,这太愚蠢了,事实上并不是原因。

    以下代码不会产生错误

    message = _("You have successfully altered ")
    message += edituser.username
    cnotes.add(message)
    message2 = '_("You may now close ")'
    cnotes.add(message2)
    

    但这并不是因为翻译,而是因为它只使用了上面两行的内容,而是因为它必须与另一个翻译有关。我迷路了。

    1 回复  |  直到 15 年前
        1
  •  1
  •   Jack M.    15 年前

    看起来好像 pickle 正在接收类型为的对象 django.utils.functional.__proxy__ . 这意味着你的输入很奇怪,或者 cnotes .

    如果你的输入有问题 金币 ,如果您查看 message S(我用了 manage.py shell ):

    >>> message = _("You have successfully altered ")
    >>> message += "Bob Knoblick"
    >>> type(message)
    <type 'unicode'>
    >>> message2 = _("You may now close ")
    >>> type(message2)
    <type 'unicode'>
    >>> 
    

    如果你的类型不是 unicode str ,我会深入研究您的代码,找出其他类型的代码来自何处,或者确保 can be pickled .

    如果里面有什么问题 金币 ,执行此操作时应获得相同的错误:

    cnotes.add(u'Foo')
    cnotes.add(u'Bar')
    cnotes.add(u'Baz')
    

    原作者:
    转换后的字符串, _("You may now close ") 不是以unicode字符串结尾。在发送到 金币 :

    message2 = unicode(_("You may now close "))