markdown Protegendoosmétodos做TemplateView

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Protegendoosmétodos做TemplateView相关的知识,希望对你有一定的参考价值。

## View
```python
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.contrib.auth.mixins import LoginRequiredMixin

# protegendo da maneira *2
# @method_decorator(login_required(login_url='/login/'), name='dispatch')
class TesteView(LoginRequiredMixin, TemplateView):
    # protegendo da maneira *3 (LoginRequiredMixin)
    template_name = 'my_app/home.html'

    def get(self, request, *args, **kwargs):
        return self.render_to_response({})

    # protegendo da maneira *1
    # @method_decorator(login_required(login_url='/login/'))
    # def dispatch(self, request, *args, **kwargs):
    #     return super().dispatch(request, *args, **kwargs)
```

## Define nos settings a URL de login padrão (LOGIN_URL)
```python
from django.urls import reverse_lazy

# ...
## necessário ter nomeado a rota de my_app para 'login'
LOGIN_URL = reverse_lazy('my_app:login')

```

以上是关于markdown Protegendoosmétodos做TemplateView的主要内容,如果未能解决你的问题,请参考以下文章

转换rst到markdown总结

markdown 用Swift 2.0编写的markdown-ish解析器

发布内容需要的Markdown语法

Markdown简易入门

Markdown中的Latex格式

Markdown Syntax 2.0