[Python] How to set and get session in Django?

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    I need to set a variable on session, when a user login happens. How can I do this?

    if request.user.is_authenticated():
    profile = request.user.get_profile()
    request.session['idempresa'] = profile.idempresa


    My other question is in a form:

    class PedidoItensForm(ModelForm):
    class Meta:
    model = ItensPedido

    def __init__(self, *args, **kwargs):
    profile = kwargs.pop('vUserProfile', None)
    super(PedidoItensForm, self).__init__(*args, **kwargs)


    How can I get the "idempresa" value of session, to use in my queryset?

    Continue reading...

Compartilhe esta Página