包含脚本在 web.py 中不起作用
大家。我想在 html 中包含 javascript(webpy 模板),但它不起作用。html 中的 javascript 代码运行得很好...
以下是主要的 python 文件(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>
包括.js:
alert('test'); //this line doesn't work
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将
include.js
文件放在项目根目录的“static/js”目录中,并且src
应为“static/js/include.js”。You must put the
include.js
file in a "static/js" directory at the root of your project andsrc
should be "static/js/include.js".