问题描述
我正在尝试将 twitch 流嵌入我的网站,但我希望流名称从 Django 模型变量继承。
这是我要开始工作的 HTML。
{% extends 'base.html' %}
{% block Title %} View Booth {% endblock %}
{% load static %}
{% block header %}
<link rel="stylesheet" href="{% static 'css/booth_profile.css' %}">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Redressed&display=swap" rel="stylesheet">
<script src="https://player.twitch.tv/js/embed/v1.js"></script>
{% endblock header %}
{% block body %}
<h1 class="fullname">{{ booth.name }}</h1>
<img src="{{ booth.cover_image.url }}" class="cover centered" alt="cover pic">
<div class="mb-4">
{% ifequal booth user.booth.first %}
<a href="{% url 'new_artwork' booth.pk %}" class="btn btn-primary">New Artwork</a>
{% endifequal %}
Live Stream:
<p id="demo">{{ booth.twitch_name }}</p>
<div id="twitch-embed"></div>
<script src="https://embed.twitch.tv/embed/v1.js"></script>
<div id="twitch-embed">
{# <iframe#}
{# id="chat_embed"#}
{# src="https://www.twitch.tv/embed/lec/chat?parent=www.google.com"#}
{# height="500"#}
{# width="350">#}
{#</iframe>#}
</div>
</div>
<div class="details">
<b>Name:</b> {{booth.name}}<br>
<b>Description:</b> {{ booth.description }}
</div>
{% for artwork in booth.artworks.all %}
<br>
Name: {{ artwork.name }}<br>
Description: {{ artwork.description }}<br>
<img src="{{ artwork.image.url }}" class="cover centered" alt="cover pic">
<br>
Price: {{ artwork.price }}<br>
{% endfor %}
<script type="text/javascript">
var twitch_name = {{ booth.twitch_name }};
new Twitch.Player("twitch-embed",{
width: 854,height: 480,channel: twitch_name
});
</script>
{% endblock %}
展位模型:
class Booth(models.Model):
name = models.CharField(max_length=50)
description = models.CharField(max_length=200)
twitch_name = models.CharField(max_length=50)
cover_image = models.ImageField()
created_by = models.ForeignKey(User,on_delete=models.CASCADE,related_name='booth')
和视图:
def viewBooth(request,pk):
booth = Booth.objects.get(pk=pk)
return render(request,'viewbooth.html',{'booth': booth})
截至目前,如果我在 twitch_name javascript 变量中手动写入流名称,它可以正常工作,但是一旦我切换 django 模型,它就会中断,我不知道为什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)