Reputation: 2901
Is there a way to display line breaks in a rendered Django string?
contact_message = "Name: %s | Email: %s" % (
form_name,
form_email,
)
For example, the code above currently prints as:
Name: <rendered name> | Email: <rendered email>
Is there a way to make it print like this:
Name: <rendered name>
Email: <rendered email>
I will be using the send_mail function, so I am hoping to make the readability more visually appealing.
Thank you!
Upvotes: 2
Views: 4140
Reputation: 312
if you want just to have a new line you can just do it with:
contact_message = "Name: %s \n Email: %s" % (
form_name,
form_email,
)
Upvotes: 1
Reputation: 14369
When sending mail, a simple \n
should be enough:
contact_message = "Name: %s\nEmail: %s" % (
form_name,
form_email,
)
This won't work in HTML, there you need HTML tags and then you have to mark the string as safe: https://docs.djangoproject.com/en/1.8/ref/utils/#module-django.utils.safestring
Upvotes: 3