On 15 Sty, 10:28, Andrew Turner <[email protected]> wrote: > I have a custom filter parses a CharField for usernames marked with > '@', and replaces them with a hyperlink to their profile page:- > > (...) > > I'm trying to mark_safe only the hyperlinks so that they are not > autoescaped, but mark_safe only seems to work if I apply it to the > returned string as a whole, which would be unsafe. > > Is this at all possible? >
I'm not 100% sure, but after doing quick review of django/utils/ safestring.py, I would say that string is either safe or unsafe, it cannot be only half-safe. (Disclaimer - Django license applies :) http://code.djangoproject.com/browser/django/tags/releases/1.1.1/LICENSE): def mark_safe(s): """ Explicitly mark a string as safe for (HTML) output purposes. The returned object can be used everywhere a string or unicode object is appropriate. Can be called multiple times on a single string. """ if isinstance(s, SafeData): return s if isinstance(s, str) or (isinstance(s, Promise) and s._delegate_str): return SafeString(s) if isinstance(s, (unicode, Promise)): return SafeUnicode(s) return SafeString(str(s)) -- Tomasz Zielinski http://pyconsultant.eu
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

