[Django-india] striptags messes spaces

Gaurav Dadhania gaurav.dadhania at gmail.com
Fri Oct 17 23:34:59 CEST 2014


That's not the Django strip_tags function that's escaping HTML, as you can
see here: https://gist.github.com/GVRV/9d392691b7452dc4e0c1

That's just the default Django templates which HTML escaping of variables.
See: https://gist.github.com/GVRV/c3d4af2fbac4322e922c

Cheers,
G

On Fri, Oct 17, 2014 at 10:27 PM, Arun Kumar Dharuman <arundhaj at gmail.com>
wrote:

> 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/20141018/72ef7e6b/attachment-0001.html>


More information about the Django-india mailing list