SAE新浪云Python添加Django模块

目前SAE预装模块中提供的Django版本包括1.2.7,1.4和1.5,暂不包含1.6及以上版本。

SAE Python可以添加自定义版本的Django模块,假设当前代码版本号为1,步骤如下:

1. 修改1/mysite/wsgi.py文件,将内容变更为:


import os
import sys

root = os.path.dirname(__file__)

sys.path.insert(0, os.path.join(root, '..', 'site-packages'))
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

2. 在1/目录下创建目录site-packages

3. 将django目录copy至1/site-packages中

写一个简单的视图,显示Django的版本号


# -*- coding: utf-8 -*-
from django.http import HttpResponse
import django
def home(request):
	return HttpResponse('Django Version = ' + str(django.VERSION), mimetype="text/plain")

返回结果为:Django Version = (1, 6, 2, 'final', 0)

本文链接:http://bookshadow.com/weblog/2014/04/23/sae-python-django-diy/
请尊重作者的劳动成果,转载请注明出处!书影博客保留对文章的所有权利。

如果您喜欢这篇博文,欢迎您捐赠书影博客: ,查看支付宝二维码