django安装
pip install django创建工程
django-admin startproject mysite启动服务器
python manage.py runserver
在浏览器输入 http://127.0.0.1:8000/ 看看创建app
python manage.py startapp polls
节奏上面四部 结构基本搭建好了。写第一个视图
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")为了调用这个视图,我们需要把它定向到一个URL,因此我们需要一个URLconf
在polls目录下创建urls.py 在urls.py配置文件中,导入views
from django.conf.urls import url
form . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]将根URLconfig指向polls.urls模块,在mysite/urls.py添加一条import用于
django.conf.urls.include和插入include()的urlpatterns列表
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),
]
已经绑定了一个index view 到URLconf。启动服务
python manage.py runserver 到 http://localhost:8000/polls/ 看下是否可用