Created
November 7, 2011 21:47
-
-
Save dtcooper/1346300 to your computer and use it in GitHub Desktop.
Conditional decorator to escape strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from django.utils.safestring import mark_safe | |
def raw_html(func_or_str): | |
''' | |
Call me a string or decorator a function with me to output HTML in your template. | |
''' | |
if callable(func_or_str): | |
@wraps(func_or_str) | |
def decorated(*args, **kwargs): | |
return mark_safe(func_or_str(*args, **kwargs)) | |
return decorated | |
else: | |
return mark_safe(func_or_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment