強大的python必需要有強大的web框架,今天開始學習django,但願各位路過的多多指點python
一 安裝djangolinux
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
二 測試web
[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項目和appdjango
[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
四 配置djangosession
[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>')
五 啓動djangoapp
[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,公告裏面有ide