我想在成功更新后重定向到另一个视图,这是我的代码
模板
<div class="col-sm-6 col-sm-offset-3">
<h3>{% trans "Editar información" %}</h3>
<form method="post" action="">
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="{% trans 'Confirmar' %}" />
<input type="hidden" name="pk" value="{{ request.user.id }}" />
</form>
</div>
urls.py
from django.contrib.auth.decorators import login_required as LR
url(r'^editperfil/(?P<pk>\d+)/$' , LR(EditarPerfil.as_view()), {}, name="editar_perfil"),
url(r'^edituser/(?P<pk>\d+)/$' , LR(EditarUsuario.as_view()), {}, name="editar_user"),
这是我的观点
class EditarUsuario(UpdateView):
model=User
form_class=EditUserForm
template_name = "editarUsuario.html"
def get_success_url(self):
return reverse('editar_perfil', args=(), kwargs={'pk':"pk" })
我需要pk参数,但我不知道如何获得它。
答案 0 :(得分:0)
试试这个:
from django.core.urlresolvers import reverse_lazy
class EditarUsuario(UpdateView):
model=User
form_class=EditUserForm
template_name = "editarUsuario.html"
def get_success_url(self):
return reverse_lazy('editar_perfil', args = (self.object.id,))