Re: How to set redirect_field_name in LoginView

43 views
Skip to first unread message

James Schneider

unread,
Jul 21, 2017, 4:49:21 AM7/21/17
to django...@googlegroups.com


On Jul 14, 2017 4:12 AM, "Polina Ia" <paulina....@gmail.com> wrote:
Hello, 
can someone explain me the setting 'redirect_field_name' in LoginView?

I have following in my urls.py:

url('^login/$', LoginView.as_view(template_name='accounts/login.html')

Now it is redirected by default to 'next'=/accounts/profile/. I'd like to set my own url for redirect. Is it better to set 'next' value in view? Or  'redirect_field_name' in urls?

I doubt 'redirect_field_name' is what you want to change.  It refers to the hidden field name within the HTML form that contains the URL that will be used for the successful redirect, not the URL itself. 

What you are probably looking for is the 'success_url', which controls where a request is redirected on the view side. 

You can set this in urls.py if you are using the generic auth views/classes. You can also set it as a class variable if you are overriding those views. Alternatively,  you can also override get_success_url() in your view class.

-James

Reply all
Reply to author
Forward
0 new messages