如何在表单发布后在django中显示javascript警报?

如何在表单发布后在django中显示javascript警报?,javascript,python,django,Javascript,Python,Django,我想显示带有消息“未找到记录”的javascript警报。: 我如何实施: if no_record_check==0: alert('No record found') // here return render('action') 将no\u record\u check作为模板上下文变量从视图中传递。例如: def get_context_data(self, **kwargs): context = super(YourViewClass, s

我想显示带有消息“未找到记录”的javascript警报。:

我如何实施:

 if no_record_check==0:
        alert('No record found') // here
        return render('action')

no\u record\u check
作为模板上下文变量从视图中传递。例如:

def get_context_data(self, **kwargs):
    context = super(YourViewClass, self).get_context_data(**kwargs)
    context['no_record_check'] = int(<your code>)
    return context
def获取上下文数据(self,**kwargs):
context=super(YourViewClass,self)。获取上下文数据(**kwargs)
上下文['no_record_check']=int()
返回上下文
然后,在模板中:

<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>

var no_record_check={{no_record_check}};//无记录检查**必须**为整数
如果(无记录检查==0){
警报(“未找到记录”);
}

警报会显示错误消息,但您需要在上下文中传递
无记录检查
,以便稍后检查是否需要显示错误消息:

return render('action.html', {'no_record_check': no_record_check})
然后在模板
action.html
(显示错误栏的引导方式)中:

{%如果没有记录\u检查==0%}
未找到任何记录
{%endif%}

name错误:未定义全局名称“render”:我已定义:从django.shortcuts导入render\u到\u响应
render\u到\u响应
不是
render
使用
从django.shortcuts导入render
{% if no_record_check == 0 %}
   <div class="alert alert-error">
        <strong>No Record Found</strong>
    </div>
{% endif %}