“Anmeldung erforderlich Django” Code-Antworten

So importieren Sie Anmeldung in Django erforderlich

from django.contrib.auth.decorators import login_required

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

Login_Requeur auf der Klasse 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_Requeur auf der Klasse 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

Anmeldung erforderlich 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

Django Login erforderlich

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

Ähnliche Antworten wie “Anmeldung erforderlich Django”

Fragen ähnlich wie “Anmeldung erforderlich Django”

Weitere verwandte Antworten zu “Anmeldung erforderlich Django” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen