D
D
Dmitry Filyushin2016-01-04 18:27:23
Django
Dmitry Filyushin, 2016-01-04 18:27:23

How to set/read cookie in django login form?

Can you please tell me how to install and then read cookies in the built-in registration form of the framework?

@login_required(login_url='/login')
def index(request):
....

redirects like this:
url(r'^login/$', 'cconline.views.card_login'),
...

def card_login(request, *args, **kwargs):
    """
    Авторизация, истечение срока сессии - 1 день
    :param request:
    :param args:
    :param kwargs:
    :return:
    """
    if request.method == 'POST':
        if not request.POST.get('remember_me', None):
            request.session.set_expiry(0)
        else:
            request.session.set_expiry(86400)
    return login(request, *args, **kwargs)

I want the value of the last login to be saved in the login input field, without a password, of course. I can not understand where to install and read the cookie

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-01-14
@Filyushin

The mailing came to me rather late. :) The question is somehow strangely formulated, in the form of registration through `request.session`, it is even used in the view from your example.
https://docs.djangoproject.com/en/1.9/topics/http/...
Don't forget to tweak SessionMiddleware.
Do you want the login that was used in the last successful authorization to be substituted in the authorization form? Set with a signal, details here
https://docs.djangoproject.com/en/1.9/ref/contrib/...
The form also has access to request, an example is here stackoverflow.com/questions/2373867/django-access- ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question