用了半天時間,把Django的基本結構同步到SAE上了,裏邊比較麻煩的地方以下:html
1. 數據庫的同步; SAE用的是SQL數據庫,默認使用下面的用戶名、密碼等變量(SAE爲咱們作了不少工做)python
首先須要修改mysite下的setting.py,以實現線上和線下操做:mysql
import os sql
if 'SERVER_SOFTWARE' in os.environ:
from sae.const import (
MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASS, MYSQL_DB
)
else:
MYSQL_HOST = 'localhost'
MYSQL_PORT = '3306'
MYSQL_USER = 'XXXX'
MYSQL_PASS = 'XXXXXX'
MYSQL_DB = 'blog'數據庫
DATABASES = {django
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': MYSQL_DB, # Or path to database file if using sqlite3.
'USER': MYSQL_USER, # Not used with sqlite3.
'PASSWORD': MYSQL_PASS, # Not used with sqlite3.
'HOST': MYSQL_HOST, # Set to empty string for localhost. Not used with sqlite3.
'PORT': MYSQL_PORT, # Set to empty string for default. Not used with sqlite3.
}
}oracle
而後,在本地建立數據庫: python manage.py syncdbapp
接下來把本地mysql中對應的數據庫導出(sql格式), 命令: mysqldump -hlocalhost -uroot -p mblog >database-name.sqlpost
最後登陸 www.sinaapp.com, 進入應用 ->MySQL管理,選擇圖形界面下的Import,把sql文件導進去。這裏還有一個小問題是上面命令導出的sql文件裏會有Lock table, Unlock table的操做,SAE是不識別的,須要刪掉。postgresql
2. 登陸 yoursite.com/admin,沒有CSS效果的解決辦法
1)修改 settings.py
#從新定向admin模塊的CSS路徑
ADMIN_MEDIA_PREFIX = '/static/admin/'
#指定靜態文件的位置,即CSS文件的位置
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. os.path.join(os.path.dirname(__file__), '../templates').replace('\\','/'), )