Django 1.10官方文档:https://docs.djangoproject.com/en/1.10/intro/tutorial01/
1.查看django版本
python -m django --version
2.创建项目
django-admin startproject mysite
3.调试工程
python manage.py runserver [8080/0.0.0.0:8000]
4.创建APP
python manage.py startapp polls
5.编辑APP视图(polls/views.py)
from django.http import HttpResponse def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
6.编辑APP链接(polls/urls.py)
from django.conf.urls import url from . import views urlpatterns = [
url(r'^$', views.index, name='index'),
]
7.编辑工程urls.py
# mysite/urls.py
from django.conf.urls import include, url
from django.contrib import admin urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
按照上面的流程就可以做出一个helloworld网页了
运行服务器(python manage.py runserver)后可以通过http://127.0.0.1:8000/polls访问
通过第一篇Tutorial里Get到的技能有:怎么用命令创建一个django工程,怎么调试运行一个工程,怎么在工程里创建一个APP,怎么设置APP与主工程url的交互,怎么设置APP内部的内容和内部url交互。