How to work with UpdateView and Forms in the template

0

I'm trying to render a client's data in the template, but I'd like to do it without using {{ form.as_p }} or {{ form.as_table }} whatever, I'd like to know if there's any way to use the id of the clients in question and use inputs in template in place of "form", I have tried everything here, I know that if I enter the shell of django I get the id just of the form, but even with id in hand I can not get the client to be rendered for editing, the fields appear however blank.

Detail : With CreateView this method of getting the form ids worked, however I want the same to happen with UpdateView .

Thanks in advance for your attention.

    
asked by anonymous 26.01.2016 / 14:46

1 answer

0

If you just want to display a customer's data in a template, you can use DetailView

link

class ClienteDetailView(DetailView):
    model = Cliente
    template_name = 'clientes/detail.html'

The problem of displaying the blank fields is perhaps because in your url you have put some other parameter to the id, not pk.

#urls.py
url(r'^(?P<pk>\d+)/editar/$', ClienteUpdateView.as_view(), name='cliente_update'),

#views
class ClienteUpdateView(UpdateView):
    model = Cliente
    form_class = ClienteForm
    template_name = 'clientes/update.html'


#listagem de clientes
...
   <a href="{% url 'clientes:cliente_update' pk=cliente.id %}">Editar</a>
...

link

    
26.01.2016 / 16:24