“diperlukan login Django” Kode Jawaban

cara mengimpor login yang diperlukan dalam django

from django.contrib.auth.decorators import login_required

@login_required(login_url='/example url you want redirect/')
Energetic Echidna

Login_required di kelas Django

You can add the decorator in the urls.py

from django.contrib.auth.decorators import login_required
 url(r'^workers/$', login_required(views.RootWorkerView.as_view()))
BlueMoon

Login_required di kelas Django

now you can use Django builtin LoginRequiredMixin

from django.contrib.auth.mixins import LoginRequiredMixin

class MyView(LoginRequiredMixin, View):
    login_url = '/login/'
    redirect_field_name = 'redirect_to'
BlueMoon

Login Dibutuhkan Django

from django.conf import settings
from django.shortcuts import redirect

def my_view(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
    # ...
Puzzled Puffin

diperlukan login Django

def login_view(request):
    if request.method == 'GET':
        cache.set('next', request.GET.get('next', None))

    if request.method == 'POST':
        # do your checks here

        login(request, user)

        next_url = cache.get('next')
        if next_url:
            cache.delete('next')
            return HttpResponseRedirect(next_url)

    return render(request, 'account/login.html')
Gleaming Guanaco

LoginRequiredMixin Django

from django.contrib.auth.mixins import LoginRequiredMixin

class MyView(LoginRequiredMixin, View):
    login_url = '/login/'
    redirect_field_name = 'redirect_to'
Fragile Fox

Jawaban yang mirip dengan “diperlukan login Django”

Pertanyaan yang mirip dengan “diperlukan login Django”

Lebih banyak jawaban terkait untuk “diperlukan login Django” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya