python - Django csrf_token in ModelAdmin -
i want add form list display of modeladmin, can't csrf_token render properly. i'm using django 1.6. code looks this:
class applicationadmin(admin.modeladmin): model = application list_display = ('applicant', 'approve_or_reject') def approve_or_reject(self, obj): return '<form method="post" action="/applications/approvals">{% csrf_token %}<input type="submit" class="btn-approve" name="approve" value="approve"/></form>' approve_or_reject.short_description = 'approve/reject' approve_or_reject.allow_tags = true admin.site.register(application, applicationadmin)
i keep getting error:
keyerror @ /management/application/ '% csrf_token %'
how can pass csrf_token?
model admin methods used in list_display
approve_or_reject
should return text. if mark output safe, can return html. however, return value not treated django template language, using csrf token tag won't work.
it wouldn't easy csrf token inside approve_or_reject
method, because not have access request object. issue entire changelist table wrapped in form tag (id="changelist-form"
), , form tags should not nested.
an alternative implement 'approve or reject' functionality admin action. ui different, might enough.
Comments
Post a Comment