including script doesn't work in web.py

自作多情 提交于 2019-12-25 08:57:45

问题


everyone.I wanna include javascript in the html(webpy templates),but it doesn't work.the javascript code in the html works very well...

following is the main python file(main.py):

urls = ('/main','main')
render = web.template.render('templates/')

class main:
  def GET(self):
    return render.main()

app = web.application(urls,globals())

if __name__ == "__main__":
  app.run()

templates/main.htm:

<body>
<script type="text/javascript" src="include.js"></script>
<script>
  alert(location.href);  //this line works..
</script>
</body>

include.js:

alert('test');  //this line doesn't work

回答1:


You must put the include.js file in a "static/js" directory at the root of your project and src should be "static/js/include.js".



来源:https://stackoverflow.com/questions/6289446/including-script-doesnt-work-in-web-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!