Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » text in via model html out in template [RSS Feed]

#1 Dec. 23, 2010 10:23:49

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

text in via model html out in template


re phrased heading as this is the real problem

model:
data = models.TextField(help_text='This is the embedding popup code for the
video', null=True, blank=True)

method:
def data(self):
return self.data
data.allow_tags = True

template:
{% for v in x %}
{{ v.data|safe }}
{% endfor %}

result:
<bound method Video.data of <Video: Part 1 >>

o/p on screen:
>

what I actually want is the output of data as html

what am I missing here?
--
View this message in context:http://old.nabble.com/text-in-via-model-html-out-in-template-tp30520062p30520062.htmlSent from the django-users mailing list archive at Nabble.com.

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

Offline

#2 Dec. 23, 2010 10:29:15

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

text in via model html out in template


On Thursday, December 23, 2010 10:23:40 AM UTC, MikeKJ wrote:
>
>
> re phrased heading as this is the real problem
>
> model:
> data = models.TextField(help_text='This is the embedding popup code for the
> video', null=True, blank=True)
>
> method:
> def data(self):
> return self.data
> data.allow_tags = True
>
> template:
> {% for v in x %}
> {{ v.data|safe }}
> {% endfor %}
>
> result:
> <bound method Video.data of <Video: Part 1 >>
>
> o/p on screen:
> >
>
> what I actually want is the output of data as html
>
> what am I missing here?
>

You have two attributes on your model called 'data'. One is the field, and
one is a method. Normally, when you reference a method in a template, Django
calls it automatically and uses the return value. However, it's possible
that because you have one name for two attributes, you've confused the
rendering engine. Try getting rid of the method altogether - it seems
irrelevant, since it just returns the value of the field - or at least
renaming it.
--
DR.

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

Offline

#3 Dec. 23, 2010 12:45:56

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

text in via model html out in template


On 23 déc, 11:23, MikeKJ <mike.jo...@paston.co.uk> wrote:
> re phrased heading as this is the real problem
>
> model:
> data = models.TextField(help_text='This is the embedding popup code for the
> video', null=True, blank=True)
>
> method:
>     def data(self):

Look no further - this method shadows the instance attribute. Since
everything in Python is an object - classes, functions and methods
included -, there's no notion of "data attribute" vs "method", you
only have attributes, all living in the same namespace.

>         return self.data
>     data.allow_tags = True

The solution is simple: rename either your model field or the method.

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

Offline

#4 Dec. 23, 2010 12:52:23

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

text in via model html out in template


On 23 déc, 11:29, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
> You have two attributes on your model called 'data'. One is the field, and
> one is a method.

Nope, there's only one : the method. You *can not* have two attributes
by the same name in a class - since attributes are stored in dict
(actually a DictProxy for classes but that's not the point) and you
obviously can't have the same key twice in a dict.


> Normally, when you reference a method in a template, Django
> calls it automatically and uses the return value.

And that's what happening here. The problem is that the data method
returns itself.

> However, it's possible
> that because you have one name for two attributes, you've confused the
> rendering engine. Try getting rid of the method altogether - it seems
> irrelevant, since it just returns the value of the field

Not quite - cf above. And the OP added this accessor so it could
tagged it with "allow_tags" (cf contrib.admin doc).

> - or at least
> renaming it.

That's indeed the solution.

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

Offline

#5 Dec. 23, 2010 14:06:49

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

text in via model html out in template


changed as below
but still not getting html out just text


MikeKJ wrote:
>
> re phrased heading as this is the real problem
>
> model:
> data = models.TextField(help_text='This is the embedding popup code for
> the video', null=True, blank=True)
>
> method:
> def data_chunk(self):
> return self.data
> data_chunk.allow_tags = True
>
> tried this as well as data = cat.data
> view:
> cat = Category,objects.get(pk=cat_id)
> data=cat.data_chunk()
>
> template:
> {{ data|safe }}
>
>
>
> result:
> text on screen not html
>
> o/p on screen:
> text
>
> what I actually want is the output of data as html
>
> what am I missing here?
>

--
View this message in context:http://old.nabble.com/text-in-via-model-html-out-in-template-tp30520062p30521999.htmlSent from the django-users mailing list archive at Nabble.com.

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

Offline

#6 Dec. 23, 2010 15:41:44

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

text in via model html out in template


solution found and I apologise for this
I forgot to mention that the input to the field was (note was) a tiny-mce
textfield and in doing that it escaped the html into the database and that
was the cause of oozlum bird effect.



bruno desthuilliers-7 wrote:
>
>
>
> On 23 déc, 11:23, MikeKJ <mike.jo...@paston.co.uk> wrote:
>> re phrased heading as this is the real problem
>>
>> model:
>> data = models.TextField(help_text='This is the embedding popup code for
>> the
>> video', null=True, blank=True)
>>
>> method:
>>     def data(self):
>
> Look no further - this method shadows the instance attribute. Since
> everything in Python is an object - classes, functions and methods
> included -, there's no notion of "data attribute" vs "method", you
> only have attributes, all living in the same namespace.
>
>>         return self.data
>>     data.allow_tags = True
>
> The solution is simple: rename either your model field or the method.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
>

--
View this message in context:http://old.nabble.com/text-in-via-model-html-out-in-template-tp30520062p30523047.htmlSent from the django-users mailing list archive at Nabble.com.

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

Offline

  • Root
  • » Django
  • » text in via model html out in template [RSS Feed]

Board footer

Moderator control

Enjoy the 21st of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support