0👍
✅
Pass no_record_check
as template context variable from the view. For example:
def get_context_data(self, **kwargs):
context = super(YourViewClass, self).get_context_data(**kwargs)
context['no_record_check'] = int(<your code>)
return context
Then, in your template:
<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>
👤jpic
1👍
Alerts are annoying show an error message instead, but you need to pass no_record_check
in context to check later if you need to display the error message or not:
return render('action.html', {'no_record_check': no_record_check})
Then in template action.html
(bootstrap way of displaying error bar):
{% if no_record_check == 0 %}
<div class="alert alert-error">
<strong>No Record Found</strong>
</div>
{% endif %}
- [Answer]-Django check if postgresql server running
- [Answer]-Migrating a model to a new app in Django 1.7.2 fails with ValueError at FK
- [Answer]-How to ignore null dates when sorting using django-filter
- [Answer]-Django – auto populating the fields in the models
Source:stackexchange.com