Django add / remove form without multiple submit

前端 未结 3 795
旧巷少年郎
旧巷少年郎 2021-01-15 00:01

I want a simple edit / remove form in Django.

I want it to look like:

Item A   edit  /   remove
Item B   edit  /   remove
Item C   edit  /   remove
<         


        
3条回答
  •  -上瘾入骨i
    2021-01-15 00:20

    You would probably do better not using a Form to achieve this, as there are (from what you've described) no form elements required.

    Instead you could have a setup in which your urls.py has 2 urls,

    url(r'^app/edit/(?P.*)$', edit_view, name='item_edit'),
    url(r'^app/remove/(?P.*)$', remove_view, name='item_remove'),
    

    And the interface you described above is generated by a template which simply uses {% url %} tag to make hyperlinks to those addresses. Say, for example, you are passing the variable 'items' in your context, you template code would look like this

    
    {% for item in items %}
        
    {% endfor %}
    
    {{item.name}} {% url 'item_edit' item.id %} {% url 'item_remove' item.id %}

    ...or something to all that effect...

提交回复
热议问题