django LOGIN_REDIRECT_URL с динамическим значением

Вот некоторые примеры:

decimal a = 1.994444M;

Math.Round(a, 2); //returns 1.99

decimal b = 1.995555M;

Math.Round(b, 2); //returns 2.00

Вы могли бы также хотеть посмотреть на банкиров, округляющихся / раунд-к-ровному со следующей перегрузкой:

Math.Round(a, 2, MidpointRounding.ToEven);

существует больше информации о нем здесь .

7
задан sa125 22 October 2009 в 16:03
поделиться

1 ответ

A solution, is to redirect to a static route like '/userpage/' and have that redirect to the final dynamic page.

But I think the real solution is to make a new view that does what you really want.

from django.contrib.auth import authenticate, login
from django.http import HttpResponseRedirect

def my_view(request):
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            HttpResponseRedirect('/%s/'%username) 
        else:
            # Return a 'disabled account' error message
    else:
        # Return an 'invalid login' error message.

http://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-web-requests

for more information about rewriting the view. This is how the docs say to override this kind of thing.

17
ответ дан 6 December 2019 в 10:51
поделиться
Другие вопросы по тегам:

Похожие вопросы: