Trying to print data containing a space in html

159 views
Skip to first unread message

anjal...@gmail.com

unread,
Jan 10, 2017, 2:09:34 AM1/10/17
to Django users
I have a data attached with multiple spaces, I want to print the data on html page along with spaces but in html spaces are getting stripped off. I found a solution of creating a package as nbsp and use that in template. I tried that but it is throwing error as "
'nbsp' is not a registered tag library
I am able to import nbsp package which I have kept in templatetags directory explicitly in python interactive mode "python manage.py shell".
Below is the code details:
nbsp.py:
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@register.filter()
def nbsp(value):
    return mark_safe(" ".join(value.split(' ')))
html:
{% load nbsp %}
{% for x in data %}
      {{ x | nbsp }}
{% endfor %}

Pleas let me know ur suggestions where I am going wrong.


Thanks in Advance,
Anjali

Asad Jibran Ahmed

unread,
Jan 10, 2017, 2:40:11 AM1/10/17
to django...@googlegroups.com
Hi Anjali,
 Where inside your project are you storing the nbsp.py file?
Regards,

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/75478ccd-feed-4835-9e67-4474a2bfc246%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anjali Mk -X (anmk - WIPRO LIMITED at Cisco)

unread,
Jan 10, 2017, 3:44:11 AM1/10/17
to django...@googlegroups.com

Asad,

 

 

My Application directory hierarchy is like this:

Project  is “mysite”, Application within the project mysite is “webpage”

mysite

      |_ webpage

                  |_  __init__.py

                  |_  views.py

                  |_   urls.py

                  |_   models.py

                  |_  static

                  |_  templates

      |_ mysite

                  |_     __init__.py

                  |_ settings.py

                  |_ urls.py

                  |_ admin.py

                  |_ templatetags

                                       |_     __init__.py

                                       |_     nbsp.py               

 

 

Regards,

 

banner7

 

Anjali Mk

Engineer - Software

an...@cisco.com

Tel: 8 066 3356

Cisco Systems, Inc.

No: 72 & 73, Keonics Electronics City Hosur Main Road
BANGALORE
560100
India
cisco.com

 

http://www.cisco.com/assets/swa/img/thinkbeforeyouprint.gifThink before you print.

This email may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message.

Please click here for Company Registration Information.

--

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

 

--

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...@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Asad Jibran Ahmed

unread,
Jan 10, 2017, 3:57:21 AM1/10/17
to django...@googlegroups.com
Can you try moving the templatetags directory to be underneath the webpage directory. I think that templatetags should be a part of an app.

Right now your templatetags are under the mysite folder, which if I'm not wrong isn't considered an app.
Regards,

--

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

ludovic coues

unread,
Jan 10, 2017, 5:28:29 AM1/10/17
to django...@googlegroups.com
load only search for python module in apps specified in INSTALLED_APPS in settings.py. So either moving templatetags to the webpage folder or adding mysite to INSTALLED_APPS would help.


For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Anjali Mk -X (anmk - WIPRO LIMITED at Cisco)

unread,
Jan 10, 2017, 5:49:44 AM1/10/17
to django...@googlegroups.com

Thanks much Asad !!!!!

It works just awesome by just moving the templatetags directory to webpage directory J

 

 

Regards,

Anjali

 

banner7

 

Anjali Mk

Engineer - Software

an...@cisco.com

Tel: 8 066 3356

Cisco Systems, Inc.

No: 72 & 73, Keonics Electronics City Hosur Main Road
BANGALORE
560100
India
cisco.com

 

http://www.cisco.com/assets/swa/img/thinkbeforeyouprint.gifThink before you print.

This email may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message.

Please click here for Company Registration Information.

 

From: django...@googlegroups.com [mailto:django...@googlegroups.com] On Behalf Of Asad Jibran Ahmed
Sent: Tuesday, January 10, 2017 2:27 PM
To: django...@googlegroups.com
Subject: Re: Trying to print data containing a space in html

 

Can you try moving the templatetags directory to be underneath the webpage directory. I think that templatetags should be a part of an app.

Regards,

--

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
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...@googlegroups.com.

--

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...@googlegroups.com.

 

--

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...@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Matthew Pava

unread,
Jan 10, 2017, 10:18:44 AM1/10/17
to django...@googlegroups.com

You might want to consider just wrapping the text in a <pre> </pre> tag.

<pre>{% for x in data %}{{ x }}{% endfor %}</pre>

 

From: django...@googlegroups.com [mailto:django...@googlegroups.com] On Behalf Of Asad Jibran Ahmed
Sent: Tuesday, January 10, 2017 1:39 AM
To: django...@googlegroups.com
Subject: Re: Trying to print data containing a space in html

 

Hi Anjali,

Regards,

--

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

 

--

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...@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Reply all
Reply to author
Forward
0 new messages