On Fri, Apr 29, 2016 at 07:18:28AM -0700, Dariusz Mysior wrote:
> Hej ja po angielsku słabo piszę, chciałem się nauczyć Class Based View i na
> tym zrobić system rejestracji, masz pomysł jak to dalej zrobić? Chciałbym
> wyciagnąć pk i dodać do adresu succes_url...
Heh, Michal, nie Michał. (-: O krajinu vedľa (Slovensko).
Anyway, while I can read Polish more or less OK, I'm clueless at
writing, so I'll try this in English again.
What I suggest is that you leave your view as it was, and create
another one just to redirect the user::
class LoginView(FormView):
template_name = 'login_form.html'
model = MysiteUser
form_class = AuthenticationForm
success_url = '/users/profile/'
class CurrentUserProfileView(RedirectView):
def get_redirect_url(self):
return reverse('profile-view', pk=
self.request.user.pk)
And, of course, then you have to add it to urls.py::
from users.views import RegisterView, LoginView, ProfileView, CurrentUserProfileView
urlpatterns = [
url(r'^register/$', RegisterView.as_view(), name='register-view'),
url(r'^login/$', LoginView.as_view(), name='login-view'),
url(r'^profile/$', CurrentUserProfileView.as_view(), name='current-profile-view'),
url(r'^profile/(?P<pk>\d+)/$', ProfileView.as_view(), name='profile-view'),
]
Michal