I want to insert a link to a page inside of my project using the Django error messages something like this
messages.error(request, 'Please click <a href="{% url 'myproject:settings' %} >here </a>')
Try using format_html
:
from django.utils.html import format_html
from django.core.urlresolvers import reverse
message = format_html('Please click <a href="{}">here</a>', reverse('myproject:settings'))
messages.error(request, message)
Using format_html
means that the string will be marked as safe, so the <a>
tag should work. Note that I've used reverse
rather than {% url %}
, because treating the string as Django template language would be trickier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With