On 7/02/2015 8:32 AM, Andrew Pinkham wrote:
I'm currently running Django 1.7.4. Provided the following clean function on a
form:
def clean_slug(self):
new_slug = self.cleaned_data['slug'].lower()
if new_slug == 'invalid_value':
raise ValidationError(
# _ is ugettext
mark_safe(_('SlugField may not be '
'"%(slug_value)s" '
'for URL reasons.')),
params={
'slug_value':
mark_safe('<code>invalid_value</code>')})
return new_slug
Have you tried removing mark_safe from the body of the method and
applying it at the end? ...
return mark_safe(new_slug)
Mike
I expect the HTML error output to read:
<li>SlugField may not be "<code>create_list</code>" for URL
reasons.</li>
Instead, the HTML output is:
<li>SlugField may not be "<code>create_list</code>" for
URL reasons.</li>
Meaning, the user sees the <code> tags as opposed to having them output as HTML.
The problem occurs when I remove the call to ugettext as well, and while I
expect to only need to apply mark_safe to the value in params, I apply the
function to all of the text above.
Am I doing something silly? How do I properly apply mark_safe to text passed to
params of exceptions? What is the best-practice here?
Thanks,
Andrew
PS
I promise to add a code to my ValidationError before committing.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/54D54E61.5000109%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.