一、Python Django的安装
一、Django的安装
# wget https://www.djangoproject.com/m/releases/1.3/Django-1.3.7.tar.gz --no-check-certificate
# tar -zxvf Django-1.3.7.tar.gz
# cd Django-1.3.7
# python setup.py install
# python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>
二、创建工程项目
# django-admin.py startproject csvt01
# cd csvt01/
# ls
__init__.py(包) manage.py(管理工具) settings.py(当前工程配置) urls.py(URL配置文件)
三、添加应用
# vi setting.py
TIME_ZONE = ‘Asia/Shanghai‘
LANGUAGE_CODE = ‘zh-cn‘
INSTALLED_APPS = (
‘django.contrib.auth‘,
‘django.contrib.contenttypes‘,
‘django.contrib.sessions‘,
‘django.contrib.sites‘,
‘django.contrib.messages‘,
‘django.contrib.staticfiles‘,
‘blog‘, #自定义一个应用,把用户定义的应用添加到这里
)
四、修改访问URL
# vi urls.py
urlpatterns = patterns(‘‘,
url(r‘^blog/index/$‘,‘blog.views.index‘),
)
五、启动应用
# django-admin.py startapp blog
# ls blog
__init__.py(包) models.py(模型文件) tests.py(测试文件) views.py(视图文件)
六、添加视图文件
# vim blog/views.py
from django.http import HttpResponse
def index(req):
return HttpResponse(‘<h1>hello welcome</h1>‘)
七、通过nginx proxy转发8000端口
# vi /etc/nginx/conf.d/django.conf
server {
listen 80 default_server;
server_name _;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
八、启动工程
# python manage.py runserver
Validating models...
0 errors found
Django version 1.3.7, using settings ‘csvt01.settings‘
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[09/Aug/2016 16:42:28] "GET /blog/index/ HTTP/1.0" 200 22
# nohup python manage.py runserver &
(后台启动Django)
通过浏览器打开http://192.168.116.129/blog/index/