django篇 一 django的安裝和測試

   強大的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,公告裏面有












發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章