How to pass variable from python to javascript

前端 未结 2 1238
说谎
说谎 2021-01-26 11:13

I have a server in python to process an id (the id of youtube video), this is the code:

class MessageHandler(tornado.web.RequestHandler): 
  def get(self, action         


        
2条回答
  •  花落未央
    2021-01-26 11:48

    It looks like you're using Tornado. You can write raw Python in a Tornado template. Your player.js file is a Tornado template in this case. You would want to update it like this:

    var PushPlayer = (function () {
    
    var player = null;
    
    function new_player() {
        player = new YT.Player('yt-player', {
            videoId: {{ action_id }},
            }
        });
    }
    

    Anthing inside the double curly braces will be evaluated as Python by Tornado.

提交回复
热议问题