1、请求周期

m = models.ManyToMany('UserGroup')


class UserGroup(models.Model):
name = ....


obj = User.objects.get(id=1)
obj.m.add(2)
obj.m.add(2,3)
obj.m.add(*[1,2,3])

obj.m.remove(...)

obj.m.clear()


obj.m.set([1,2,3,4,5])

# 多个组,UserGroup对象
obj.m.all()
obj.m.filter(name='CTO')



知识点:
URL
- 两个
Views
- 请求的其他信息
from django.core.handlers.wsgi import WSGIRequest
request.environ
request.environ['HTTP_USER_AGENT']
- 装饰器
FBV:
def auth(func):
def inner(reqeust,*args,**kwargs):
v = reqeust.COOKIES.get('username111')
if not v:
return redirect('/login/')
return func(reqeust, *args,**kwargs)
return inner

CBV:
from django import views
from django.utils.decorators import method_decorator

@method_decorator(auth,name='dispatch')
class Order(views.View):

# @method_decorator(auth)
# def dispatch(self, request, *args, **kwargs):
# return super(Order,self).dispatch(request, *args, **kwargs)

# @method_decorator(auth) #使用CBV的时候需要把auth当做参数传入django的装饰器类里面
def get(self,reqeust):
v = reqeust.COOKIES.get('username111')
return render(reqeust,'index.html',{'current_user': v})

def post(self,reqeust):
v = reqeust.COOKIES.get('username111')
return render(reqeust,'index.html',{'current_user': v})
Templates
- 母版...html
extends
include
- 自定义函数
simple_tag
a. app下创建templatetags目录
b. 任意xxoo.py文件
c. 创建template对象 register
d.
@register.simple_tag
def func(a1,a2,a3....)
return "asdfasd"
e. settings中注册APP
f. 顶部 {% load xxoo %}
g. {% 函数名 arg1 arg2 %}
缺点:
不能作为if条件
优点:
参数任意
filter
a. app下创建templatetags目录
b. 任意xxoo.py文件
c. 创建template对象 register
d.
@register.filter
def func(a1,a2)
return "asdfasd"
e. settings中注册APP
f. 顶部 {% load xxoo %}
g. {{ 参数1|函数名:"参数二,参数三" }} {{ 参数1|函数名:数字 }}
缺点:
最多两个参数,不能加空格
优点:
能作为if条件

分页(自定义的分页)

XSS:
{{ page_str|safe }}

mark_safe(page_str)

cookie
客户端浏览器上的一个文件
{"user": 'dachengzi'}

session :装饰器


Models
- 一大波操作

Form验证
-
缓存
中间件
信号
CSRF
Admin/ModelForm

作业:
主机管理:
1、单表操作
2、一对多
3、多对多
要求:
a. 删除对话框
b. 修改,添加新URL
c. 基于cookie进行用户认证
d. 定制显示个数
e. 分页
预习:
Form: http://www.cnblogs.com/wupeiqi/articles/6144178.html
Model:http://www.cnblogs.com/wupeiqi/articles/6216618.html


相关文章:

  • 2021-10-03
猜你喜欢
  • 2021-09-14
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-10
  • 2021-12-14
相关资源
相似解决方案