jazzband / django-embed-video

Django app for easy embedding YouTube and Vimeo videos and music from SoundCloud.
http://django-embed-video.rtfd.org
MIT License
383 stars 135 forks source link

Video not showing on frontend #105

Closed reyesvicente closed 5 years ago

reyesvicente commented 5 years ago

Hi,

I'm new in using this package. I followed the docs and everything is smooth sailing. But the videos won't show on the front end. On the admin, I placed the URL of a YouTube video for the models video = EmbedVideoField(verbose_name='Videos', help_text='Videos of Translation') and

{% video object.video as amlvideo %}
Backend: {{ amlvideo.backend }}
URL: {{ amlvideo.url }}
Code: {{ amlvideo.code }}
Thumbnail: {{ amlvideo.thumbnail }}
HTTPS: {% if amlvideo.protocol == 'https' %}Yes{% else %}No{% endif %}

{% video amlvideo "large" %}
{% endvideo %}
on my template but it's not showing. Here are my ```models.py```
from embed_video.fields import EmbedVideoField

class AMLVideo(models.Model):

    LANGUAGE = (
        ('LAN', 'Language'),
        ('FR', 'French'),
        ('EN', 'English'),
        ('HIN', 'Hindi'),
        ('SPA', 'Spanish'),
        ('GER', 'German'),
    )

    LEVEL = (
        ('BEG', 'Beginner'),
        ('INT', 'Intermediary'),
        ('ADV', 'Advanced'),
    )

    CATEGORY = (
        ('ANI', 'Animal'),
        ('ENV', 'Environmental'),
        ('MOR', 'Moral'),
        ('FOLK', 'Folktales'),
        ('ADN', 'Adventure'),
        ('POE', 'Poems'),
        ('FUN', 'Funny'),
    )

    title = models.CharField(max_length=100, default=None)
    level = models.CharField(max_length=100, choices=LEVEL)
    language = models.CharField(max_length=100, choices=LANGUAGE)
    category = models.CharField(max_length=100, choices=CATEGORY)
    video = EmbedVideoField(verbose_name='Videos',
                            help_text='Videos of Translation')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "video"
        verbose_name_plural = "videos"
What could I do with this?
aleksihakli commented 5 years ago

Hey! Do you have the embed_video application in your INSTALLED_APPS as per the documentation?

What is your video URL? The package only supports YouTube, Vimeo, and SoundCloud videos at the moment. You can check out the support in the backends module.

Do you get a stacktrace or error of any kind from your templates or applications when you add the video or try to access it in your views?

reyesvicente commented 5 years ago

Hey! Do you have the embed_video application in your INSTALLED_APPS as per the documentation?

What is your video URL? The package only supports YouTube, Vimeo, and SoundCloud videos at the moment. You can check out the support in the backends module.

Do you get a stacktrace or error of any kind from your templates or applications when you add the video or try to access it in your views?

Yes, I have the embed_video on my INSTALLED_APPS.

I added the youtube URL on the Django Admin as a super user. Once I hit submit, the video got embedded INSIDE the admin, not on the template.

I saw a thumbnail error from one of the tags if I remember it correctly.

aleksihakli commented 5 years ago

Well, it seems the admin works, so the problem is most likely with your template and HTML rendering. I'd check and fix any errors there first. YouTube videos should work correctly if they are public.

reyesvicente commented 5 years ago

Well, it seems the admin works, so the problem is most likely with your template and HTML rendering. I'd check and fix any errors there first. YouTube videos should work correctly if they are public.

What's the easiest way to show it on the template? I need a row of 3 youtube videos.

How would you fix this?


Backend: {{ amlvideo.backend }}
URL: {{ amlvideo.url }}
Code: {{ amlvideo.code }}
Thumbnail: {{ amlvideo.thumbnail }}
HTTPS: {% if amlvideo.protocol == 'https' %}Yes{% else %}No{% endif %}

{% video amlvideo "large" %}
{% endvideo %}```
reyesvicente commented 5 years ago

I got this error Backend wasn't recognised (``) Traceback (most recent call last): File "/Users/user/Dev/Django/planetread/env/lib/python3.7/site-packages/embed_video/templatetags/embed_video_tags.py", line 112, in render backend = self.get_backend(url, context=context, **options) File "/Users/user/Dev/Django/planetread/env/lib/python3.7/site-packages/embed_video/templatetags/embed_video_tags.py", line 164, in get_backend else detect_backend(str(backend_or_url)) File "/Users/user/Dev/Django/planetread/env/lib/python3.7/site-packages/embed_video/backends.py", line 62, in detect_backend raise UnknownBackendException embed_video.backends.UnknownBackendException

aleksihakli commented 5 years ago

If you take a look at the source code where the error happens you can see that the backend URL should be included in the error message, but it seems like your URL isn't resolved in the video template tag correctly.

You are most probably using the template wrong and need to fix it. Try and remove lines one by one and see which line(s) break the functionality, then fix those parts.

The amount of source code in this package is fairly small so reading through the relevant error lines in the repository should prove helpful.

Roshik33 commented 4 years ago

I got this error Backend wasn't recognised () Traceback (most recent call last): File "/Users/user/Dev/Django/planetread/env/lib/python3.7/site-packages/embed_video/templatetags/embed_video_tags.py", line 112, in render backend = self.get_backend(url, context=context, options) File "/Users/user/Dev/Django/planetread/env/lib/python3.7/site-packages/embed_video/templatetags/embed_video_tags.py", line 164, in get_backend else detect_backend(str(backend_or_url)) File "/Users/user/Dev/Django/planetread/env/lib/python3.7/site-packages/embed_video/backends.py", line 62, in detect_backend raise UnknownBackendException embed_video.backends.UnknownBackendException `` This solved by error** @reyesvicent .. bind the video inside the for

home.html

{% load embed_video_tags %}

{% for items in allitems %}

{{items.title}}

{% video items.video as my_video %} {% video my_video "large" %} {% endvideo %} {% video my_video '800x600' %}
{% endfor %}

views.py def home(request): allItems= Item.objects.all() context= {'allitems': allItems} return render(request, 'post/post_detail.html',context)

models.py

from embed_video.fields import EmbedVideoField class Item(models.Model): title = models.CharField(max_length=50) video = EmbedVideoField(verbose_name="My video", help_text="This is a help text") def unicode(self): return self.title

reyesvicente commented 4 years ago

Posting a solution for the benefit of everyone:

...
{% load embed_video_tags %}
{% video item.video 'small' %}
...

{% if videos %}
{% for v in videos %}
{% video v.video as my %}
<iframe width="{{ 380 }}" height="{{ 225 }}" src="{{ my.url }}" frameborder="0" allowfullscreen></iframe>
{% endvideo %}
{% endfor %}