Уведомления

Группа в Telegram: @pythonsu

#1 Апрель 7, 2008 10:38:38

securelord
От:
Зарегистрирован: 2006-08-31
Сообщения: 129
Репутация: +  0  -
Профиль   Отправить e-mail  

Django auth username

Ламерский вопрос: как в овьювере вытащить username вошедшего пользователя?



Офлайн

#2 Апрель 7, 2008 11:22:15

pochechyev
От:
Зарегистрирован: 2008-02-29
Сообщения: 199
Репутация: +  0  -
Профиль   Отправить e-mail  

Django auth username

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

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



Офлайн

#3 Апрель 7, 2008 12:11:04

securelord
От:
Зарегистрирован: 2006-08-31
Сообщения: 129
Репутация: +  0  -
Профиль   Отправить e-mail  

Django auth username

pochechyev

Не совсем то. Это если я передаю имя из формы входа.
А необходимо в произвольной функции viewes.py получить имя вошедшего пользователя (аутентифицированного).



Офлайн

#4 Апрель 7, 2008 12:21:48

slivlen
От:
Зарегистрирован: 2006-07-06
Сообщения: 764
Репутация: +  0  -
Профиль   Отправить e-mail  

Django auth username

authed_user = None
if request.user.is_authenticated():
    authed_user = request.user.username



Офлайн

#5 Апрель 7, 2008 13:12:33

securelord
От:
Зарегистрирован: 2006-08-31
Сообщения: 129
Репутация: +  0  -
Профиль   Отправить e-mail  

Django auth username

slivlen

А разве у user есть метод username? У него помоему что то типа - first_name, last_name…



Офлайн

#6 Апрель 7, 2008 14:42:23

playpauseandstop
От:
Зарегистрирован: 2007-10-31
Сообщения: 77
Репутация: +  0  -
Профиль   Отправить e-mail  

Django auth username

А разве у 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)



Офлайн

#7 Апрель 7, 2008 17:19:01

securelord
От:
Зарегистрирован: 2006-08-31
Сообщения: 129
Репутация: +  0  -
Профиль   Отправить e-mail  

Django auth username

playpauseandstop
Спасибо, разобрался.



Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version