Issue
I've been banging my head against the wall for a while now on this problem. Here is what I'm doing: Creating a Django website that populates different pages with Twitch livestreams. It's a learning project to use API in a web application.
I have built a models Class Stream:
...
class Stream(models.Model):
name = models.CharField(max_length=100)
pub_date = models.DateTimeField('date published')
channel = models.CharField(max_length=300)
...
Now I pass that info to my views.py
...
def media(request, media_id):
specificMedia = get_object_or_404(Stream, pk=media_id)
channel = str(specificMedia.channel)
return render(request, 'livestream/media.html', {'specificMedia': specificMedia, 'channel': channel})
finally this reaches my template which looks like this:
<!DOCTYPE html>
<html>
<head>
</head>
<body bgcolor="#B0B0B0">
<p>Media Title: {{ specificMedia.name }}</p>
<p>Date: {{specificMedia.pub_date}}</p>
<p>Channel: {{channel}}</p>
<p><div id="urldata">content</div></p>
<object type="application/x-shockwave-flash"
height="378"
width="620"
id="live_embed_player_flash"
data= <div id="urldata">content</div>
bgcolor="#000000">
<param name="allowFullScreen"
value="true" />
<param name="allowScriptAccess"
value="always" />
<param name="allowNetworking"
value="all" />
<param name="movie"
value="http://www.twitch.tv/widgets/live_embed_player.swf" />
<param name="flashvars"
value= <div id="urlvalue">content</div>
</object>
<script>
var data = "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + {{channel}};
document.getElementById('urldata').innerHTML = urldata;
</script>
</body>
</html>
Now here is my difficulty. I can get {{channel}}
to display the correct twitch channel, but when I try to make the URL strings in the Object for the twitch API everything falls apart. If anyone could help that would be greatly appreciated.
Solution
Change
<script>
var data = "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + {{channel}};
document.getElementById('urldata').innerHTML = urldata;
</script>
To
<script>
var data = "http://www.twitch.tv/widgets/live_embed_player.swf?channel={{channel}}";
document.getElementById('urldata').innerHTML = urldata;
</script>
Answered By - nickromano
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.