* Daniel Gerzo <dge...@gmail.com> [2011-04-25 13:07:46 +0200]:

> On 25.4.2011 12:40, Kane Dou wrote:
> >* Daniel Gerzo<dge...@gmail.com>  [2011-04-24 17:52:13 +0200]:
> >
> >>Hello all,
> >>
> >>say I have a following form:
> >>
> >>class MyForm(forms.Form):
> >>     id = forms.IntegerField(max_length=9)
> >>     language = forms.CharField(max_length=10)
> >>     file = forms.FileField()
> >>
> >>And a following pseudo clean method:
> >>
> >>     def clean(self):
> >>         for file in self.files.values():
> >>             if file_exists(file):
> >>                 raise forms.ValidationError('We already have this
> >>file<a href="/somehwere">here</a>')
> >>         return self.cleaned_data
> >>
> >>So I want to display a URL in the error message. The text is
> >>displayed fine, but the URL is being escaped by Django and thus is
> >>not clickable. Is there some way to disable it for this specific
> >>case?
> >>
> >>The form is being rendered like:
> >>
> >>     <form enctype="multipart/form-data" method="post" action=""
> >>id="upload">{% csrf_token %}
> >>     <table>
> >>         {{ form.as_table }}
> >>         <tr><td><input type="submit" value="Upload"
> >>/></td><td><input type="reset" value="Reset" /></td></tr>
> >>     </table>
> >>     </form>
>
> >
> >You may check the 'safe'[1] filter
> >
> >
> >[1]  http://docs.djangoproject.com/en/1.3/ref/templates/builtins/#safe
>
> Hello Kane,
>
> thanks for your reply. I already tried |safe previously, as
>
> {{ form.as_table|safe }}
>
> but that doesn't work, the hyperlink is still being escaped. Maybe I
> need to do something else in this case?
>
> I even tried:
>
>         {% autoescape off %}
>         {{ form.as_table }}
>         {% endautoescape %}
>
> Doesn't work either. Maybe the validation errors are being escaped
> prior they being passed to the template itself? How can I turn that
> off?
>
> Thanks.
>

Try to render the form in separate parts:

{{ form.<field>.label }}
{{ form.<field>.errors|safe }}
{{ form.<field> }}

This works, but I'm not sure if this is a good or right practice.

--
Kane

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to