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

Javascript .js文件未提供给开发服务器,javascript,html,Javascript,Html,我的html文件引用了静态文件夹中的.js文件,该文件夹与.html文件目录(模板)不同。当我运行.html文件时,它工作正常,因为加载了.js文件。问题是,如果我在本地服务器上运行应用程序,我会收到错误消息: GET http://localhost:63342/UniteMessageBoard/templates/%5CUniteMessageBoard%5Cstatic%5Cjquery.js [HTTP/1.1 404 Not Found 1ms] 并且脚本不会加载 这是我的h

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

 GET http://localhost:63342/UniteMessageBoard/templates/%5CUniteMessageBoard%5Cstatic%5Cjquery.js   [HTTP/1.1 404 Not Found 1ms]
并且脚本不会加载

这是我的
html
code:

<!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>
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'
    }
 });
 }
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)
main.py
code:

<!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>
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'
    }
 });
 }
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服务器希望它们是
/
。因此,在本地访问文件时,无需通过web服务器,它就可以工作,但一旦到达服务器,它就会中断。

将斜线向前划。没有人再对目录使用反斜杠了。信不信由你,如果html文件在templates文件夹中,这是唯一有效的方法。如果它在templates文件夹之外,
/static/jquery.js
工作得很好,但我也遇到了同样的问题。好的……你能发布你的目录树吗?是的,我也试过了,但仍然不起作用。@bjb568我已经更新了问题。请看一下。由于UniteMessageBoard是您的根目录,带有
index.html
,您不应该需要src中的
UniteMessageBoard
部分。因此,请尝试使用
src=“/static/jquery.js”
使其基于根目录,这样您的站点的根目录,即
UniteMessageBoard
您应该只使用
/
作为文件路径,并且您应该只通过web服务器查看页面。