修复 decorator 导致 swagger 无法识别注释的问题
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
from functools import wraps
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
@@ -7,6 +8,7 @@ from .models import User
|
|||||||
|
|
||||||
|
|
||||||
def login_required(func):
|
def login_required(func):
|
||||||
|
@wraps(func)
|
||||||
def check(*args, **kwargs):
|
def check(*args, **kwargs):
|
||||||
# 在class based views 里面,args 有两个元素,一个是self, 第二个才是request,
|
# 在class based views 里面,args 有两个元素,一个是self, 第二个才是request,
|
||||||
# 在function based views 里面,args 只有request 一个参数
|
# 在function based views 里面,args 只有request 一个参数
|
||||||
@@ -21,6 +23,7 @@ def login_required(func):
|
|||||||
|
|
||||||
|
|
||||||
def admin_required(func):
|
def admin_required(func):
|
||||||
|
@wraps(func)
|
||||||
def check(*args, **kwargs):
|
def check(*args, **kwargs):
|
||||||
request = args[-1]
|
request = args[-1]
|
||||||
if request.user.is_authenticated() and request.user.admin_type:
|
if request.user.is_authenticated() and request.user.admin_type:
|
||||||
|
|||||||
Reference in New Issue
Block a user