How to use use_library('django','1.2&#

2019-07-04 06:02发布

I'm learning developing in Google App Engine.

This is one of the code from the tutorial, http://code.google.com/appengine/docs/python/gettingstarted/usingwebapp.html

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication(
                                     [('/', MainPage)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

I've almost identical code. I sometime get warning:

WARNING 2011-06-30 13:10:44,443 init.py:851] You are using the default Django version (0.96). The default Django version will change in an App Engine release in the near future. Please call use_library() to explicitly select a Django version. For more information see http://code.google.com/appengine/docs/python/tools/libraries.html#Django

Can anyone please re factor the above code with use_library(). I'm not sure how to start and where to use use_library and what to do with webapp.

Thanks in advance.

3条回答
▲ chillily
2楼-- · 2019-07-04 06:40

In the current version this is even simpler as third-party libraries are now specified in app.yaml

libraries:
- name: django
  version: "1.2"

You can also use webapp2 that includes Django’s templating engine.

import webapp2
from google.appengine.ext.webapp2 import template
查看更多
唯我独甜
3楼-- · 2019-07-04 06:45

try putting this code on top of your module :

import os
from google.appengine.dist import use_library
use_library('django', '1.2')
查看更多
We Are One
4楼-- · 2019-07-04 06:54

The above code should not require you to call use_library directly.

If you create a new file in the root directory of your application named appengine_config.py and add the following line to it:

# Make webapp.template use django 1.2
webapp_django_version = '1.2'
查看更多
登录 后发表回答