这段代码片段在做什么? (来自Google App Engine Django示例)

时间:2011-04-22 01:06:16

标签: django google-app-engine

我想知道这个片段到底是做什么的? (见http://code.google.com/p/google-app-engine-samples/source/browse/trunk/django_example/django_bootstrap.py

# Make sure we can import Django.  We may end up needing to do this
# little dance, courtesy of Google third-party versioning hacks.  Note
# that this patches up sys.modules, so all other code can just use
# "from django import forms" etc.
try:
  from django import v0_96 as django
except ImportError:
  pass

1 个答案:

答案 0 :(得分:3)

正如我之前在another question中所述,你可以在app引擎中使用不同的django版本(目前从0.96到1.2)。默认情况下,它仍然使用0.96作为django(这是此代码片段的作用)。虽然您可以通过向main.py添加以下内容来更改此内容:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from google.appengine.dist import use_library
use_library('django', '1.2')