gpt4 book ai didi

python - “WSGIRequest”对象在 Google App Engine 中没有属性 'user'

转载 作者:太空宇宙 更新时间:2023-11-04 06:30:18 25 4
gpt4 key购买 nike

我是 django 和 Google App Engine 的新手,在使用数据存储区时遇到了问题。每次我进行查询时,例如

db.GqlQuery("SELECT * FROM Listing ORDER BY date DESC LIMIT 10")

我收到错误:

'WSGIRequest' object has no attribute 'user'

这个错误似乎是在 django 核心的 context_processors.py 中产生的。现在,我在网上找到的建议说要注释掉与用户相关的INSTALLED_APPS 和MIDDLEWARE_CLASSES,但这似乎没有帮助。我的代码如下所示:

MIDDLEWARE_CLASSES = (
# 'django.middleware.common.CommonMiddleware',
# 'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.middleware.doc.XViewMiddleware',
)

INSTALLED_APPS = (
# 'django.contrib.auth',
'django.contrib.contenttypes',
# 'django.contrib.sessions',
'django.contrib.sites',
)

我的 Listing 对象定义如下(它之前有一个 author 属性,但现在被注释掉了,对象被重新定义了一个新名称):

class Listing(db.Model):
#author = db.UserProperty()
address = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
coords = db.GeoPtProperty()

有谁知道导致此错误的原因以及如何解决?是否可能需要以某种方式重置设置?

最佳答案

更新

sdolan建议的解决方案似乎是在app的settings.py中添加如下内容:

TEMPLATE_CONTEXT_PROCESSORS = ( “django.core.context_processors.debug”, "django.core.context_processors.i18n")

这有效地删除了第三个默认处理器 django.core.context_processors.auth(它不应该存在,因为对于 AppEngine,我们不需要 Django 的 auth 组件)。

谢谢 sdolan 的解决方案!希望其他人也可以使用它。 :)

@Nick,我认为值得将关于 CONTEXT_PROCESSORS 的黄金篇放在教程中 (http://code.google.com/appengine/articles/django.html)

(问题的原始跟进)

有同样的问题,正在寻找解决方案....当settings.py包含时一切正常

调试 = 真

但是当我切换到

时,这个错误弹出(并扼杀了我继续学习的动力)

调试 = 错误

@Nick Johnson,这是堆栈跟踪:

Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3211, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3154, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 527, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2404, in Dispatch
self._module_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2314, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2212, in ExecuteOrImportScript
script_module.main()
File "C:\Dev\appengine\djangotest\main.py", line 37, in main
util.run_wsgi_app(application)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\util.py", line 97, in run_wsgi_app
run_bare_wsgi_app(add_wsgi_middleware(application))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\util.py", line 115, in run_bare_wsgi_app
result = application(env, _start_response)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\handlers\wsgi.py", line 189, in __call__
response = self.get_response(request)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\handlers\base.py", line 103, in get_response
return callback(request, **param_dict)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\views\defaults.py", line 79, in page_not_found
return http.HttpResponseNotFound(t.render(RequestContext(request, {'request_path': request.path})))
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\context.py", line 100, in __init__
self.update(processor(request))
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\context_processors.py", line 18, in auth
'user': request.user,
AttributeError: 'WSGIRequest' object has no attribute 'user'

关于python - “WSGIRequest”对象在 Google App Engine 中没有属性 'user',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3692853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com