繁体   English   中英

.js文件未提供给开发服务器

[英].js files not being served to development server

我的html文件引用了static文件夹中的.js文件,该文件夹与.html文件目录(模板)不同。 当我运行.html文件时,由于加载了.js文件,它工作正常。问题是,如果我在本地服务器上运行应用程序,则会收到错误消息:

 GET http://localhost:63342/UniteMessageBoard/templates/%5CUniteMessageBoard%5Cstatic%5Cjquery.js   [HTTP/1.1 404 Not Found 1ms]

并且脚本不会加载。

这是我的html代码:

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="text/javascript" src="\UniteMessageBoard\static\jquery.js"></script>
<script type="text/javascript" src="\UniteMessageBoard\static\script.js"></script>

</head>
<body>
    <h1> {{ title }} </h1>
<input type="button" id="submit2" value="get it">
</body>
</html>

和我的script.js代码:

console.log('loaded script.js');

$(document).ready(function () {

$("#submit2").on('click', function (event) {
    handleClick();
});

});


function handleClick() {
  alert("We got here");
    $.ajax('/', {
    type: 'GET',
    data: {
        fmt: 'json'
    }
 });
 }

main.py代码:

JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)



class MainHandler (webapp2.RequestHandler):
   def get(self):

    self.templateValues = {}
    self.templateValues['title'] = 'jQuery JSON Tutorial 2'
    template = JINJA_ENVIRONMENT.get_template('templates/base.html')
    self.response.out.write(template.render(self.templateValues))


  app = webapp2.WSGIApplication([
   ('/.*', MainHandler)

   ], debug=True)

如果我在本地运行应用程序,这是我得到的错误代码:

 [HTTP/1.1 200 OK 18ms]

即使实际上并未加载。

编辑:这是我的目录树:

在此处输入图片说明

几乎可以肯定,您正在Windows盒上进行开发。 我可以说是因为\\而不是/ 问题是您在localhost上运行的Web服务器希望这些服务器为/ 因此,在本地访问文件,而无需通过网络服务器即可工作,但是一旦到达服务器,它就会中断。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM