How to make a new line in django messages.error
Question:
I have a line of my code
messages.error(request, ('ERROR: upload failed. Try again'))
popping up a message in my template
upload failed. Try again
But I want to get a new line after the point, like:
upload failed.
Try again
How do I get that?
I tryed
upload failed.n Try again
and
upload failed.<br/> Try again
and
upload failed.{{text|linebreaks}} Try again
but it does not work…
Answers:
You almost made it. You need to use mark_safe.
In your case, this is what you will have:
from django.utils.safestring import mark_safe
messages.error(request, mark_safe("ERROR: upload failed.<br/>Try again"))
This might not be a perfect solution for your case, but you can call it two times:
messages.error(request, 'ERROR: upload failed.')
messages.error(request, 'Try again')
Instead of one message of two lines, you’ll output two messages perfectly split.
I have a line of my code
messages.error(request, ('ERROR: upload failed. Try again'))
popping up a message in my template
upload failed. Try again
But I want to get a new line after the point, like:
upload failed.
Try again
How do I get that?
I tryed
upload failed.n Try again
and
upload failed.<br/> Try again
and
upload failed.{{text|linebreaks}} Try again
but it does not work…
You almost made it. You need to use mark_safe.
In your case, this is what you will have:
from django.utils.safestring import mark_safe
messages.error(request, mark_safe("ERROR: upload failed.<br/>Try again"))
This might not be a perfect solution for your case, but you can call it two times:
messages.error(request, 'ERROR: upload failed.')
messages.error(request, 'Try again')
Instead of one message of two lines, you’ll output two messages perfectly split.