I\'m trying to display a bit of html in a message that\'s being displayed via the new Django messages framework. Specifically, I\'m doing this via the ModelAdmin.message_use
You can use format_html. It applies escaping to all arguments.
For example, if we can link with a 'mymodel' detail using an attribute call 'name':
from django.contrib import messages
from django.utils.html import format_html
message = format_html("{} {}",
"This is the mymodel",
reverse('myapp:mymodel-detail', args=(mymodel.id,)),
mymodel.name)
messages.info(request, message)
This answer is based on https://stackoverflow.com/a/33751717/3816639