# 跳转用户中心
用django自带方法判断登录
```
is_authenticated
```
使用用装饰器
```python
from django.contrib.auth.decorators import login_required
# 路由装饰
login_required(views.类.as_view())
# 类继承装饰
from django.contrib.auth.decorators import login_required
class LoginRequiredMixin(object):
@classmethod
def as_view(cls, **kwargs):
view = super().as_view(**kwargs)
return login_required(view)
class 类(LoginRequiredMixin, View):
...
```
|
|