field for html

27 views
Skip to first unread message

Kovy Jacob

unread,
Aug 3, 2020, 11:05:56 AM8/3/20
to django...@googlegroups.com
Hi, is there a type of field for django data models that's for html? I want to have youtube embed links, which is a bunch of html fo putting a youtube video on your site. Itlooks like this: "<iframe width="640" height="360" src="https://www.youtube.com/embed/Rj_vssRaZlQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>". I stored it in a charfield, but it gets shown on the website as text.
What should I do?
Thanks,
Kovy

neeraj garg

unread,
Aug 3, 2020, 1:16:38 PM8/3/20
to django...@googlegroups.com
Try to use django safe filter to render this as html.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACMwF3VTKYF3Zjm9fQMFwtjvxYXdsUA1JV6mXFTrD0XBW5bDdw%40mail.gmail.com.


--
Thanks,
Neeraj

Yemin Sajid

unread,
Aug 4, 2020, 8:10:15 AM8/4/20
to django...@googlegroups.com
I would suggest you to only put the video id in the charfield and use that to render the <iframe> in the template. Otherwise, there can be security issues if the content from the charfield is rendered safely as HTML.

So in your template could it would be something like
<iframe width="640" height="360" src="https://www.youtube.com/embed/{{ video_id }}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Kovy Jacob

unread,
Aug 5, 2020, 2:49:51 PM8/5/20
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages