M
M
mstbee2016-03-12 00:28:55
Django
mstbee, 2016-03-12 00:28:55

How to redirect to specified url Django?

Doesn't redirect to success_url , instead sends to main localhost:8000

class LoginFormView(FormView):
    form_class = AuthenticationForm

    # Аналогично регистрации, только используем шаблон аутентификации.
    template_name = "registration/login.html"

    # В случае успеха перенаправим на главную.
    success_url = "/game/"

    def form_valid(self, form):
        # Получаем объект пользователя на основе введённых в форму данных.
        self.user = form.get_user()

        # Выполняем аутентификацию пользователя.
        login(self.request, self.user)
        return super(LoginFormView, self).form_valid(form)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Voronkov, 2016-03-12
@mstbee

In the settings, specify where you need to redirect:

settings.py:
...
LOGIN_REDIRECT_URL = '/game/'
...

Another option is to use the next
Url of the form:
<a href="{% url 'auth_login' %}?next=/game/">Auth</a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question