How to redirect url with argument to another page in Django? (UpdateView, GenericView)

0

Well, I have a very pertinent question. I have a django editing class, and when I edit the user, I need it to call the detail class of it (DetailView), the two classes are working, but when I call the url that sends the DetailView, it gives an error, which is obvious, since the detail view needs the user id via GET. However, how to pass this user id via get through the UpdateView class, since it uses success_url? follows the code of the said classes:

UpdateView:

class UpdateUserView(LoginRequiredMixin, IsMaintainer ,UpdateView):
    model = User
    context_object_name = 'u'
    template_name = 'update-user.html'
    fields = ['name', 'email', 'nivel']
    success_url = reverse_lazy('accounts:detail')

DetailView:

class DetailUserView(LoginRequiredMixin, IsMaintainer ,DetailView):
    model = User
    context_object_name = 'u'
    template_name = 'profile.html'
    
asked by anonymous 05.06.2017 / 16:08

1 answer

1

According to the Django 1.11 documentation - link - you can specify the URL fields using the kwargs variable.

success_url = reverse_lazy('accounts:detail', kwargs={'id': 10})

In this way I'm filling in the : id field of the route with a value of 10.

    
05.06.2017 / 18:35