简体   繁体   中英

Javascript doesn't work in my localhost using Google App ENgine

Im stuck since a week and I allready looked in a million spanish and english forums...

The thing is that Javascript does not work on my localhost when I launch my website from Google App Engine.

If I copy/paste all the html, css and .js files and then I launch in the browser from Notepad++ works perfectly, but for any reason does not work on GAE, and I don´t know why.

The app.yaml works because if I write in the browser:

http://localhost:8080/js/script.js , then appear the javascript code.

Here is all my code:

HTML:

<script type="text/javascript" src="/js/jquery.js"</script>
<script type="text/javascript" src="/js/script.js"></script>

JS:

$(document).ready(function() {
    $("#ingles").fadeOut(1000);
});

My app.yaml:

application: juanmamorenoportfolio
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: /images
  static_dir: static_files/images

- url: /js
  static_dir: js

- url: .*
  upload: templates/index.html
  static_files: templates/index.html

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest

and my main.py (I suspect the problem should be here):

import os
import webapp2
import jinja2

jinja_environment = jinja2.Environment(autoescape=True,
    loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')))

class MainHandler(webapp2.RequestHandler):
    def get(self):
        template = jinja_environment.get_template('index.html')
        self.response.out.write(template.render())

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

Many thanks!!

Javascript works perfectly on SDK and production.

  1. app.yaml is wrong - write correct path to jquery.js.
  2. Put file where is required or you point before.
  3. Check if you regex in urls specification since it is not simple strings.
  4. Maybe upload: is required in - url: .
  5. Try http://localhost:8080/js/script.js to check if code is shown.
  6. Check page if HTML is ok.
  7. Check if $ is defined in ie Chrome Console.
  8. Vote for my answer.

Read documentation Static file handlers .

是的,它与上upload: thing: 静态文件模式处理程序

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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