标签:
1.django安装
a.下载所需版本,地址:https://www.djangoproject.com/download/1.3.7/tarball/
b.解压并安装(需要root权限)
tar xf Django-1.3.7.tar.gz cd Django-1.3.7
python setup.py install
c.在python环境下import django无报错则说明安装正常。
2.第一个django程序
django-admin.py startproject favoo #用django新建一个项目
cd favoo
django-admin.py startapp blog #用django新建一个应
3.修改favoo/setting.py文件
TIME_ZONE = ‘Asia/Shanghai‘ LANGUAGE_CODE = ‘zh-CN‘ 在INSTALLED_APPS中新增‘blog‘,
4.修改favoo/url.py
url(r‘^blog/index/$‘, ‘blog.views.index‘), 新增匹配规则
5. 修改favoo/blog/views.py
from django.http import HttpResponse def index(req): return HttpResponse(‘<h1>Hello World</h1>‘)
6.启动服务
python manage.py runserver
Validating models...
0 errors found
Django version 1.3.7, using settings ‘favoo.settings‘
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
也可以指定监听的ip和端口 python manage.py runserver 0.0.0.0:8000
Validating models...
0 errors found
Django version 1.3.7, using settings ‘favoo.settings‘
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
7.访问指定的url http://127.0.0.1:8000/blog/index/
标签:
原文地址:http://www.cnblogs.com/shine009/p/4805185.html