“Impor Pengguna di Django” Kode Jawaban

Impor Pengguna di Django

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

Impor Dapatkan Django Model Pengguna

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

Dapatkan Django Pengguna

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

Jawaban yang mirip dengan “Impor Pengguna di Django”

Pertanyaan yang mirip dengan “Impor Pengguna di Django”

Lebih banyak jawaban terkait untuk “Impor Pengguna di Django” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya