Print html the normal way

17 views
Skip to first unread message

Ashish Jain

unread,
Oct 5, 2012, 4:20:41 AM10/5/12
to django...@googlegroups.com
Hi,

I wrote a simple filter as:

@register.filter()
def html(value):
    return '<p>Check</p>'

when I use this filter in my template, it displays html as:

<p>Check</p>

I want to display as:

Check

am I missing something.

- Thanks for your help
Ashish

Tom Evans

unread,
Oct 5, 2012, 4:40:09 AM10/5/12
to django...@googlegroups.com
On Fri, Oct 5, 2012 at 9:20 AM, Ashish Jain <ashishj...@gmail.com> wrote:
> Hi,
>
> I wrote a simple filter as:
>
> @register.filter()
> def html(value):
> return '<p>Check</p>'
>
> when I use this filter in my template, it displays html as:
>
> <p>Check</p>
>
> I want to display as:
>
> Check
>
> am I missing something.
>

You haven't marked the output as safe, so Django escapes it:

https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/#filters-and-auto-escaping

You want option 2.

Cheers

Tom

Ashish Jain

unread,
Oct 5, 2012, 5:02:07 AM10/5/12
to django...@googlegroups.com, teva...@googlemail.com
Hi,

Thanks a ton!!

using mark_safe() worked perfectly.

- Regards
Ashish

Laxmikant Gurnalkar

unread,
Oct 5, 2012, 2:45:41 PM10/5/12
to django...@googlegroups.com, teva...@googlemail.com
Use
 {{yourvar|html|striptags}}

Laxmikant Gurnalkar
On Fri, Oct 5, 2012 at 2:32 PM, Ashish Jain <ashishj...@gmail.com> wrote:
Hi,

Thanks a ton!!

using mark_safe() worked perfectly.

- Regards
Ashish

On Friday, 5 October 2012 14:10:31 UTC+5:30, Tom Evans wrote:
On Fri, Oct 5, 2012 at 9:20 AM, Ashish Jain <ashishj...@gmail.com> wrote:
> Hi,
>
> I wrote a simple filter as:
>
> @register.filter()
> def html(value):
>     return '<p>Check</p>'
>
> when I use this filter in my template, it displays html as:
>
> <p>Check</p>
>
> I want to display as:
>
> Check
>
> am I missing something.
>

You haven't marked the output as safe, so Django escapes it:

https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/#filters-and-auto-escaping

You want option 2.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Sz5auuOkyYcJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
GlxGuru

Reply all
Reply to author
Forward
0 new messages