1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Django 非ログインユーザはlogin.htmlへ遷移させたい時

Posted at

#クラスの場合 LoginRequiredMixin を使う

.py
from django.contrib.auth.mixins import LoginRequiredMixin
# 略
 
class Top(LoginRequiredMixin, generic.TemplateView):
    template_name = 'hogehogeapp/index.html'   ☛☛☛hogehogeappの部分はアプリケーション名を入力する

#関数の場合 login_requiredデコレータを使う

.py
from django.contrib.auth.decorators import login_required

@login_required
def hogehoge(request, pk):
    hogehoge
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?