“Benutzer in Django importieren” Code-Antworten

Benutzer in Django importieren

>>> from django.contrib.auth.models import User
>>> user = User.objects.create_user('john', '[email protected]', 'johnpassword')

# At this point, user is a User object that has already been saved
# to the database. You can continue to change its attributes
# if you want to change other fields.
>>> user.last_name = 'Lennon'
>>> user.save()
Clever Crocodile

Importieren Sie Benutzermodell Django

from django.contrib.auth import get_user_model
User = get_user_model()
Panicky Pintail

LoginRequiredMixin

from django.contrib.auth.mixins import LoginRequiredMixin

LOGIN_URL = 'your_url'
Virgin Programmer

Holen Sie sich Benutzer Django

def sample_view(request):
    current_user = request.user
    print current_user.id
Awful Alpaca

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 “Benutzer in Django importieren”

Fragen ähnlich wie “Benutzer in Django importieren”

Weitere verwandte Antworten zu “Benutzer in Django importieren” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen