开发者

How can i pass object_id to the template for (deleteing record) in Django

I have this code

book_model_delete = {
    'model' : Book, 
    'post_delete_redirect': "/boo/list/", 
    "template_name" : "books/confirm_delete.html",
   }

(r'^book/delete/(?P<object_id>\d+开发者_运维问答)/$', create_update.delete_object, book_model_delete)

The template i am using is

<form action="/book/delete/{{object_id}}/" method="post" enctype="multipart/form-data" >
    {% csrf_token %}
    Are you sure you want to delete
    <p><input type="submit" value="yes" /></p>
    </form>

Now when i click on delete then this confirmation page comes but i don't know how to get the object_id passed in URL in this template


You are probably looking for {{object.id}}:

django.views.generic.create_update.delete_object

...

Optional arguments:

...

template_object_name: Designates the name of the template variable to use in the template context. By default, this is 'object'.


A fast solution is to declare a hidden field with the value of the object_id:

<input type=hidden name="your_object_id" value="{{object.id}}"/>

and get it via request.PST in your view

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜