[Django-india] striptags messes spaces

Arun Kumar Dharuman arundhaj at gmail.com
Fri Oct 17 18:57:03 CEST 2014


forgot the mention this line,
>>> t = Template("{{ html_content|striptags }}")

2014-10-17 22:09 GMT+05:30 Arun Kumar Dharuman <arundhaj at gmail.com>:

> I'm using Django 1.7.0 (recent version)
>
> In my case for a form's textarea I'm using CKEditorWidget. When user feeds
> input with extra spaces, the widget adds   to the string.
>
> > python manage.py shell
> >>> from django.template import Context, Template
> >>> t = Template("{{ html_content }}")
> >>> c = Context({"html_content": "<html><p> This is a    sample
> html</p>     </html>"})
> >>> t.render(c)
> u' This is a   &nbsp;sample html     '
>
> Since the source string itself contains   characters, striptags
> ignores it.
>
> you can check the behavior in the below site
> http://www.bits-junction.in/quiz/1
>
>
> Regards
> ArunDhaJ
>
> 2014-10-17 18:05 GMT+05:30 Gaurav Dadhania <gaurav.dadhania at gmail.com>:
>
>> Can you please give a concrete example when it is adding the non-breaking
>> space?
>>
>> I'm not seeing this behaviour:
>> https://gist.github.com/GVRV/94479855558ef054ba0c
>>
>> Are you on an older version of Django? Maybe you'll have some luck with
>> using the `bleach` library for this purpose as recommended in the official
>> docs as a better alternative
>> https://docs.djangoproject.com/en/dev/ref/templates/builtins/#striptags
>>
>> Cheers,
>> G
>>
>>
>> On Fri, Oct 17, 2014 at 4:48 PM, Arun Kumar Dharuman <arundhaj at gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> using striptags works fine removing html tags, however it adds  
>>> for any extra spaces.
>>> how to get rid of striptags converting spaces to " "?
>>>
>>> regards
>>> ArunDhaJ
>>>
>>> _______________________________________________
>>> Django-india mailing list
>>> Django-india at python.org
>>> https://mail.python.org/mailman/listinfo/django-india
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/django-india/attachments/20141017/c41cf7b3/attachment.html>


More information about the Django-india mailing list