[英]how to set DEBUG value automatically in django on Google App Engine
I think the question says it all.. 我认为问题就说明了一切。
I want to set DEBUG=False when running on Google App Engine but want to make it True on local machine.. 我想在Google App Engine上运行时设置DEBUG = False,但要在本地计算机上设为True。
(I am not using django-nonrel) (我没有使用django-nonrel)
I do 我做
app = webapp.WSGIApplication([
...
], debug = os.environ.get('SERVER_SOFTWARE', 'Dev').startswith('Dev'))
which is like Thomas Orozco's snippet, but defaults to enabling debug if the SERVER_SOFTWARE isn't set. 就像Thomas Orozco的代码段一样,但是如果未设置SERVER_SOFTWARE,则默认启用调试功能。 That'll only happen if you happen to be using a bit of code outside of the app engine environment, so it's your call on how you want that to default.
仅当您碰巧在App Engine环境之外使用一些代码时,才会发生这种情况,因此这是您希望如何将其默认设置的电话。
Use the SERVER_SOFTWARE
environment variable. 使用
SERVER_SOFTWARE
环境变量。
As instructed in the GAE docs : 按照GAE文档中的指示:
SERVER_SOFTWARE
: In the development web server, this value is "Development/XY" where "XY" is the version of the runtime.SERVER_SOFTWARE
:在开发Web服务器中,此值为“ Development / XY”,其中“ XY”是运行时的版本。 When running on App Engine, this value is "Google App Engine/XYZ".在App Engine上运行时,此值为“ Google App Engine / XYZ”。
So just do: 所以做:
import os
def get_gae_debug():
server = os.environ.get("SERVER_SOFTWARE")
if server is None:
return False # Unexpected, disable DEBUG.
software, version = server.split("/", 1)
return software == "Development"
DEBUG = get_gae_debug()
The most recent update for this syntax (place on your app settings.py): 此语法的最新更新(放在您的应用settings.py中):
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
DEBUG = False
else:
DEBUG = True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.