Day1 创建项目
创建app
python manage.py startapp game # 创建名为game的app
初始化数据库
python manage.py migrate
创建管理员账户
python manage.py createsuperuser
目录结构
urls.py
存放路由
mkdir templates
存放HTML页面
models.py
存放class、类
views.py
存放函数
创建简单页面
# 1.在views.py中定义函数
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
# 2.在urls.py中添加路由
from django.urls import path
from game.views import index
urlpatterns = [
path('', index, name='index'),
]
# 3.在全局的app中的urls.py中include urls
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('game/', include('game.urls')),
]
#访问:http://localhost:8000/game/
#显示:Hello, world. You're at the polls index.