开发者

Putting links into text in Django

开发者 https://www.devze.com 2022-12-30 00:50 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消