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


I expect the HTML error output to read:

    <li>SlugField may not be &quot<code>create_list</code>&quot; for URL 
reasons.</li>

Instead, the HTML output is: 

    <li>SlugField may not be &quot;&lt;code&gt;create_list&lt;/code&gt;&quot; 
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/A9EEE119-BF44-48DE-8AEE-E511AEB0F544%40andrewsforge.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to