Putting links into text in Django
I have a notifications app that generates notifications for users. The notification class has to be really general, because notifications are generated by all sorts of different things.
My question is this: How do I insert links into the text of the notifications?
What I tried was this:
note = Notification(..., notification="""%s %s has accepted the task: <a href="/tasks/%d/">%s</a>.""" % (request.user.first_name, request.user.last_name, task.id, task.name), ...)
In retrospect, it's obvious thi开发者_StackOverflow社区s wouldn't work. How should I go about this? Thanks in advance!
Edit: Django is outputting the < and > characters as lt and gt
What you've got will work fine, provided that when you output the Notification, Django doesn't escape it, either using the safe
filter in your template, or mark_safe
somewhere in your view or model code.
精彩评论