我想显示带有“找不到记录”
消息的javascript提醒我该如何实施:
if no_record_check==0:
alert('No record found') // here
return render('action')
答案 0 :(得分:0)
从视图中传递no_record_check
作为模板上下文变量。例如:
def get_context_data(self, **kwargs):
context = super(YourViewClass, self).get_context_data(**kwargs)
context['no_record_check'] = int(<your code>)
return context
然后,在您的模板中:
<script type="text/javascript">
var no_record_check = {{ no_record_check }}; // no_record_check **must** be an integer
if (no_record_check == 0) {
alert('No record found');
}
</script>
答案 1 :(得分:0)
警报很烦人,而是显示错误消息,但您需要在上下文中传递no_record_check
,以便稍后检查是否需要显示错误消息:
return render('action.html', {'no_record_check': no_record_check})
然后在模板action.html
中(显示错误栏的引导方式):
{% if no_record_check == 0 %}
<div class="alert alert-error">
<strong>No Record Found</strong>
</div>
{% endif %}