VariableDoesNotExist,键[用户]的查找失败

I'm using django-guardian library to verify users permissions in an object level and I'm trying to verify that inside of the change_list_results.html template, NOTE : the same code worked just fine under change_list.html but for some reason it's not working for change_list_results.html.

(我也看到了类似的问题,但我不明白他们的回答,我觉得他们的案子对我不适用。)

here's my code, under change_list_results.html template :

{% for object in cl.result_list %}
{% get_obj_perms user for object as "context_var" %}
{% if 'college_admin' in context_var %}
<p>hi</p>
{% endif %}
{% endfor %}

The user in {% get_obj_perms user for object as "context_var" %} is causing the error.

错误:

Failed lookup for key [user] in [{'True': True, 'False': False, 'None': None}, 
{'cl': <django.contrib.admin.views.main.ChangeList object at 0x7fa319ba0a00>,
 'result_hidden_fields': [], 'result_headers': [{'text': '<input type="checkbox"
 id="action-toggle">', 'class_attrib': ' class="action-checkbox-column"',
 'sortable': False}, {'text': 'generator', 'class_attrib': ' class="column-
__str__"', 'sortable': False}], 'num_sorted_fields': 0, 'results': [['<td 
class="action-checkbox"><input type="checkbox" name="_selected_action" value="26" 
class="action-select"></td>', '<th class="field-__str__"><a href="/generator
/generator/26/change/">الهندسة</a></th>'], ['<td class="action-checkbox"><input 
type="checkbox" name="_selected_action" value="25" class="action-select"></td>',
 '<th class="field-__str__"><a href="/generator/generator/25/change/">العلوم</a>
</th>']], 'csrf_token': <SimpleLazyObject: 
'TcuMSJ6FwzuUboZtet03iJh2sPVzcHlLYa2rUGhB9Y4UDKpPPaxusKUelClRAVP3'>}]

评论