django各个文件作用,三板斧和静态文件配置

1、django中各个文件的作用

mysite # 项目名
app01 # 应用名
migrations # 数据库迁移记录
init.py
admin.py # 后台管理
apps.py # 忽略
models.py # 模型层,跟数据库打交道
tests.py # 测试文件
views.py # 视图层
mysite
init.py
settings.py # 配置文件
urls.py # 路由与视图函数的对应关系
wsgi.py # wsgiref模块
templates # 模板层,存储html文件的
manage.py # 入口文件, 启动文件
2、django三板斧

HttpResponse返回时字符串
return HttpResponse("ok")
render返回html文件
return render(request, 'index.html')
redirect跳转网址
return redirect('http://www.baidu.com')
return redirect('/home/')
3、静态配置文件

在django中,html文件存在哪?
templates
在django中,静态文件都放在static中

在settings.py最后写上
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"), # 静态文件存放位置
]

在html文件中
第一种方式:

第二种方式:
{% load static %}

什么是静态文件?
前端已经写好的,可以直接调用的
css文件
js文件
img文件
第三方框架
4、request对象

request.method # 获取当前的请求方式,并且返回的是全大写的字符串

print(request.POST.get('hobby')) # 只能接收最后一个
print(request.POST.getlist('hobby')) # 接收多个

request.GET.get('name') #只接受最后一个
request.GET.getlist('age') #接收到的是个列表

posted @ 2021-08-10 17:29  zhutianyu  阅读(428)  评论(0)    收藏  举报