using django 2.0.2 on mac os 10.13 with python 3.6.4
implementing alerts in templates
django settings.py
MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}
views.py
def list(request)
messages.error(request,'invalid user', extra_tags='alert')
return redirect('/')
templates.html
attempted implementation in 2 different ways
template1.html
{% if messages %}
<script>
{% for message in messages %}
alert({{message}})
{% endfor %}
</script>
{% endif %}
template2.html
<div class="content container">
{% if messages %}
{% for message in messages %}
<div class="alert {{ message.tags }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
{{ message }}
</div>
{% endfor %}
{% endif %}
<div class="row">
<div class="col-md-8">
result of using template2.html:
<div class="alert alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
invalid user
</div>
Is this HTML valid for displaying the image?
Having trouble implementing alerts in Django..