|
| 1 | +Web开发框架 |
| 2 | +================ |
| 3 | + |
| 4 | +Django |
| 5 | +-------------- |
| 6 | + |
| 7 | +NOTE: 目前SAE Python使用的版本是 *Django-1.2.7* , 请确保你安装的是这个版本。 |
| 8 | + |
| 9 | +1. 建立一个新的Python应用mysite |
| 10 | + |
| 11 | +2. 检出SVN代码到本地目录 |
| 12 | + |
| 13 | +3. 新建文件index.wsgi,内容如下 |
| 14 | + |
| 15 | +.. literalinclude:: ../examples/pythondemo/1/index.wsgi |
| 16 | + |
| 17 | +4. 初始化django应用 |
| 18 | + |
| 19 | +:: |
| 20 | + |
| 21 | + django-admin.py startproject mysite |
| 22 | + |
| 23 | +5. 从django安装目录复制admin 的media目录 |
| 24 | + |
| 25 | +:: |
| 26 | + |
| 27 | + cp -rf django/contrib/admin/media/ . |
| 28 | + |
| 29 | +去除.svn 目录:: |
| 30 | + |
| 31 | + find . -type d -name ".svn"|xargs rm -rf |
| 32 | + |
| 33 | +目录结构如下:: |
| 34 | + |
| 35 | + jaime@westeros:~/source/chenfeng/pythondemo/1$ ls |
| 36 | + index.wsgi media mysite README |
| 37 | + jaime@westeros:~/source/chenfeng/pythondemo/1$ ls media/ |
| 38 | + css img js |
| 39 | + jaime@westeros:~/source/chenfeng/pythondemo/1$ ls mysite/ |
| 40 | + demo __init__.py manage.py settings.py urls.py views.py |
| 41 | + jaime@westeros:~/source/chenfeng/pythondemo/1$ |
| 42 | + |
| 43 | +6. 提交代码 |
| 44 | + |
| 45 | +访问 `http://mysite.sinaapp.com` ,就可看到Django的欢迎页面了。 |
| 46 | + |
| 47 | +7. Hello, Django! |
| 48 | + |
| 49 | +在mysite/目录下新建一个views.py,内容如下 |
| 50 | + |
| 51 | +.. literalinclude:: ../examples/pythondemo/1/mysite/views.py |
| 52 | + |
| 53 | +修改urls.py,新增一条规则解析hello,同时打开admin的注释:: |
| 54 | + |
| 55 | + # Uncomment the next two lines to enable the admin: |
| 56 | + from django.contrib import admin |
| 57 | + admin.autodiscover() |
| 58 | + |
| 59 | + urlpatterns = patterns('', |
| 60 | + ... |
| 61 | + (r'^$', 'mysite.views.hello), |
| 62 | + (r'^admin/', include(admin.site.urls)), |
| 63 | + ) |
| 64 | + |
| 65 | + |
| 66 | +在setttings.py中开启admin组件:: |
| 67 | + |
| 68 | + INSTALLED_APPS = ( |
| 69 | + 'django.contrib.auth', |
| 70 | + 'django.contrib.contenttypes', |
| 71 | + ... |
| 72 | + # Uncomment the next line to enable the admin: |
| 73 | + 'django.contrib.admin', |
| 74 | + # Uncomment the next line to enable admin documentation: |
| 75 | + # 'django.contrib.admindocs', |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +提交代码,访问 `http://mysite.sinaapp.com/` |
| 80 | + |
| 81 | +Django 数据库配置见 MySQL 节。 |
| 82 | + |
| 83 | + |
| 84 | +Flask |
| 85 | +------------- |
| 86 | + |
| 87 | +index.wsgi |
| 88 | + |
| 89 | +.. literalinclude:: ../examples/pythondemo/2/index.wsgi |
| 90 | + |
| 91 | +myapp.py |
| 92 | + |
| 93 | +.. literalinclude:: ../examples/pythondemo/2/myapp.py |
| 94 | + |
| 95 | +http://2.pythondemo.sinaapp.com/demo |
| 96 | + |
| 97 | + |
| 98 | +Bottle |
| 99 | +-------------- |
| 100 | + |
| 101 | +index.wsgi |
| 102 | + |
| 103 | +.. literalinclude:: ../examples/pythondemo/3/index.wsgi |
| 104 | + |
| 105 | +http://3.pythondemo.sinaapp.com |
| 106 | + |
| 107 | + |
| 108 | +Tornado |
| 109 | +--------------- |
| 110 | + |
| 111 | +index.wsgi |
| 112 | + |
| 113 | +.. literalinclude:: ../examples/pythondemo/4/index.wsgi |
| 114 | + |
| 115 | +http://4.pythondemo.sinaapp.com |
| 116 | + |
0 commit comments