- http://www.python.org/getit/releases/2.7.3/ 找到MSI installer 下载,建议用2.7的版本
- 安装python后添加环境变量 PATH: ;C:\Python27
- 安装python package包管理工具和常用package
- 下载setuptools, http://pypi.python.org/pypi/setuptools#files 找到对应python版本下载installer安装
- 安装pip工具, http://pypi.python.org/pypi/pip 解压后命令行进入解压目录,运行 python setup.py install 然后添加环境变量 PATH: C:\Python27\Scripts
- 用pip安装各种需要的package,比如 pip install distribute ...
- 安装 Django, pip install django
- 安装 pil, pip install pil ,pil好像下载极其艰难 -_-#
- django_admin.py startproject ***
- manage.py runserver [8000]
- settings.py
import os.path fileRoot = os.path.dirname(__file__) MEDIA_ROOT = os.path.join(fileRoot, 'static') MEDIA_URL = '/site_media/'
- urls.py
from django.conf import settings if settings.DEBUG: urlpatterns += patterns("", (r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT,"show_indexes":True}), )
- templates/
<link href="/site_media/**.css" rel="stylesheet" /> <script src="/site_media/**.js"></script>
- 如果你本地没有mysql数据库,可以安装WampServer:http://www.onlinedown.net/soft/82112.htm
- 安装python db 包 python2.7 http://www.codegood.com/archives/129
- 通过WampServer操作数据库
- settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'python_hello', # Or path to database file if using sqlite3. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '3306', # Set to empty string for default. Not used with sqlite3. } }
上述配置中 NAME 字段配置前提是本地的mysql数据库中有一个叫 python_hello 的table
- 验证数据库连接成功
from django.db import connection cursor = connection.cursor()
- 新建app
python manage.py startapp ***