标签:怎么 自己 patch 方便 解决 index 文件 场景 models
from django.shortcuts import render, HttpResponse
# create your views here
def request_finished():
print(“Request finished!”)
def outer(func):
def wrapper(*args, **kwargs):
ret = func(*args, **kwargs)
request_finished()
return ret
return wrapper
@outer
def index(request):
return HttpResponse(“Hello World!”)
def my_callback(sender, **kwargs):
print(“Request finished!”)
from django.core.signals import request_finished
request_finished.connect(my_callback)
from django.core.signals import request_finished
from django.dispatch import receiver
@receiver(request_finished)
def my_callback(sender, **kwargs):
print(“Request finished!”)
def index(request):
return HttpResponse(“Hello World!”)
import django.dispatch
my_signal = django.dispatch.Signal()
from django.dispatch import receiver
@receiver(my_signal)
def my_callback(sender, **kwargs):
print(“Hello World!”)
from django.shortcuts import render, HttpResponse
def index(request):
my_signal.send(sender=my_signal)
return HttpResponse(“Hello World!”)
django.db.models.signals.pre_save & django.db.models.signals.post_save
。每次model的save()方法被调用前后,该信号将被发送。django.db.models.signals.pre_delete & django.db.models.signals.post_delete
。每次model的delete()方法被调用前后,该信号将被发送。django.db.models.signals.m2m_changed
。每次ManyToMany字段被修改都会发送该信号。django.core.signals.request_started & django.core.signals.request_finished
。开始或者结束一个HTTP请求的时候都会发送该信号。标签:怎么 自己 patch 方便 解决 index 文件 场景 models
原文地址:https://www.cnblogs.com/paulwhw/p/9380183.html