强大的python必须要有强大的web框架,今天开始学习django,希望各位路过的多多指点
一 安装django
wget http://dl2.iteye.com/upload/p_w_upload/0047/5063/dea17ea8-8bf1-34d7-87c9-7d1149be1821.gz tar zxvf dea17ea8-8bf1-34d7-87c9-7d1149be1821.gz cd Django-1.3/ python setup.py install
二 测试
[root@localhost project]# python Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> 表示安装成功
三 生成django项目和app
[root@localhost /]# mkdir /web [root@localhost /]# cd /web/ [root@localhost web]# django-admin.py startproject project #创建项目 [root@localhost web]# cd project/ [root@localhost project]# django-admin.py startapp web #创建app [root@localhost project]# ls __init__.py manage.py settings.py urls.py web
四 配置django
[root@localhost project]# vi settings.py
修改:
TIME_ZONE = 'Asia/Shanghai'
LANGUAGE_CODE = 'zh-cn'
在下面‘web‘,添加:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'web',
)
[root@localhost project]# vi urls.py
在下面添加url(r'^web/index/$', 'web.views.home'),
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'project.views.home', name='home'),
# url(r'^project/', include('project.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
url(r'^web/index/$', 'web.views.index'),
)
[root@localhost project]# vi web/views.py
from django.http import HttpResponse
def index(req):
return HttpResponse('<h1>hello</h1>')五 启动django
[root@localhost project]# python manage.py runserver 192.168.250.88:80 Validating models... 0 errors found Django version 1.3, using settings 'project.settings' Development server is running at http://192.168.250.88:80/ Quit the server with CONTROL-C.
六 测试
希望能帮得到大家,有什么疑问可以加我的QQ,公告里面有

















