Найти - Пользователи
Полная версия: Django auth username
Начало » Django » Django auth username
1
securelord
Ламерский вопрос: как в овьювере вытащить username вошедшего пользователя?
pochechyev
securelord
Ламерский вопрос: как в овьювере вытащить username вошедшего пользователя?
http://www.djangoproject.com/documentation/authentication/#how-to-log-a-user-in

...
username = request.POST['username']
...
securelord
pochechyev

Не совсем то. Это если я передаю имя из формы входа.
А необходимо в произвольной функции viewes.py получить имя вошедшего пользователя (аутентифицированного).
slivlen
authed_user = None
if request.user.is_authenticated():
    authed_user = request.user.username
securelord
slivlen

А разве у user есть метод username? У него помоему что то типа - first_name, last_name…
playpauseandstop
А разве у user есть метод username? У него помоему что то типа - first_name, last_name…
django/contrib/auth/models.py
class User(models.Model):
    """Users within the Django authentication system are represented by this model.
    Username and password are required. Other fields are optional.
    """
    username = models.CharField(_('username'), max_length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    email = models.EmailField(_('e-mail address'), blank=True)
    password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
    is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
    last_login = models.DateTimeField(_('last login'), default=datetime.datetime.now)
    date_joined = models.DateTimeField(_('date joined'), default=datetime.datetime.now)
    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
        help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
securelord
playpauseandstop
Спасибо, разобрался.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB