来源:https://docs.djangoproject.com/en/2.1/intro/tutorial01/
该教程是创建一个用于投票的网页。
1.使用命令创建site
进入要创建site的目录,输入命令:
$ django-admin startproject mysite
2.让我们来看看startproject
创造了什么:
mysite/ manage.py mysite/ __init__.py settings.py urls.py wsgi.py
3.步骤1已经创建了一个site,现在启动验证一下:
$ python manage.py runserver
4.创建投票模块
$ python manage.py startapp polls
polls的目录如下:
polls/ __init__.py admin.py apps.py migrations/ __init__.py models.py tests.py views.py
编辑polls页面的内容:
polls/views.py
from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the polls index.")
polls/urls.py
from django.urls import path from . import views urlpatterns = [ path('', views.index, name='index'), ]
mysite/urls.py
from django.contrib import admin from django.urls import include, path urlpatterns = [ path('polls/', include('polls.urls')), path('admin/', admin.site.urls), ]
mysite/settings.py 设置当地时区
TIME_ZONE = 'Asia/Shanghai'
重新启动,查看polls页面是否生效:
$ python manage.py runserver