为什么我的应用程序使用默认方法而不是我导入的方法?
我有一个上下文处理器,我试图覆盖 get_and_delete_messages
from forum.user_messages import get_and_delete_messages
def user_messages (request):
"""
Returns session messages for the current session.
"""
messages = request.user.get_and_delete_messages()
return { 'user_messages': messages }
它没有拾取我在调试会话中可以看到的用户消息:
ipdb> request.session['messages']
["only site Admins can use that feature."]
该应用程序似乎正在从用户模型 @ django.contrib.auth.models 调用 get_and_delete_messages:
而不是我导入的方法。
如何调用正确的模型?
I have a context processor where I'm trying to override get_and_delete_messages
from forum.user_messages import get_and_delete_messages
def user_messages (request):
"""
Returns session messages for the current session.
"""
messages = request.user.get_and_delete_messages()
return { 'user_messages': messages }
It's not picking up a user message that I can see in the debugging session:
ipdb> request.session['messages']
["only site Admins can use that feature."]
The app seems to be calling the get_and_delete_messages from the User model @ django.contrib.auth.models:
Instead of the method I imported.
How do I get the correct model called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您导入
get_and_delete_messages
时,您正在导入具有该名称的函数。 request.user.get_and_delete_messages 仍然绑定到之前绑定的相同函数实现。When you import
get_and_delete_messages
, you are importing a function with that name.request.user.get_and_delete_messages
is still bound to the same function implementation that it was bound to before.