一.git 上传文件到仓库
1.git init -->初始化
2.git add . -->将文件放入暂存区
3.git commit -m ‘上传说明’ —>提交到本地仓库
4.git remote add origin -->添加到新的远程仓库,origin 指代对应的仓库地址
5.git push -u origin master -->将本地的master分支推送到origin主机,同时指定origin为默认主机,后面就可以不加任何参数使用git push了。
二.Django创建应用项目
1.django-admin startapp ‘应用名’ / python manage.py startapp ‘应用名’
2.点开setting.py,找到INSTALLED_APPS -->输入’应用名’
3.点开view.py -->建立视图函数(接收来自浏览器的请求,给用户以回应)
from django.http import HttpRequest,HttpResponse
def show_index(request:HttpRequest)
content = '...'
return HttpResponse(content)
操作相对繁琐,引入render函数,用于渲染页面返回完整的响应体
from django.shortcuts import render
select_heroes = random.sample(Heroes,4) #随机选择4名英雄
return render(request,'index.html',{'heroes':select_heroes})
4.使用视图函数需要配置url映射(请求的路由) -->点开urls.py
–>URL(统一资源定位符)相对路径 --> 视图函数 -->path
from '项目名'.views import show_index
path('hello/',show_index)