源碼地址python
git clone https://gitee.com/Outsrkem/web.git
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel \ sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel yum -y install epel-release yum -y install python-pip cat << EOF > ~/.pip/pip.conf [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host=mirrors.aliyun.com EOF pip install --upgrade pip pip install django
建立模板 django-admin startproject web 建立項目 python manage.py startapp myweb 應用項目(若是是遷移過來的) python manage.py migrate 啓動項目 python manage.py runserver
web/ ├── db.sqlite3 ├── manage.py ├── myweb │ ├── admin.py │ ├── apps.py │ ├── __init__.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── tests.py │ └── views.py └── web ├── __init__.py ├── settings.py # 總配置文件 ├── urls.py ├── wsgi.py
./web/web/settings.py
修改監聽地址git
ALLOWED_HOSTS = ['10.10.10.35','127.0.0.1'] # 表明監聽2個IP ALLOWED_HOSTS = ['*'] # 表明監聽本機全部IP
啓動web
python manage.py runserver 0:8000 # 0:8000 表明使用配置的ip地址
修改根路由 web/web/urls.py sql
from django.conf.urls import url,include from django.contrib import admin urlpatterns = [ #url(r'^admin/', admin.site.urls), url(r'^', include('myweb.urls')), ]
修改子路由 web/myweb/urls.pydjango
from django.conf.urls import url from django.contrib import admin from . import views urlpatterns = [ #url(r'^admin/', admin.site.urls), url(r'^hello/', views.hello), ]
建立視圖函數 web/myweb/views.py centos
from django.shortcuts import render from django.http import HttpResponse # Create your views here. def hello(request): return HttpResponse('hello word')
頁面訪問 10.10.10.35:8000/hello app