简体   繁体   中英

app.yaml configuration in Google App Engine

My project is simple, it contains a folder its name templates where index.html is located, and another folder called static contains another folder called js where a simple JavaScript file is located its name is myScript.js.

The problem that I am facing is the configuration of app.yaml (I think that I am not doing it correct), because if I include the JavaScript code in index.html everything works fine, but when I am placing the JavaScript file outside index.html then the application doesn't run correct.

Here is my app.yaml configuration

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

handlers:

- url: .*
  script: main.app


- url: /js
  static_dir: static/js

- url: /index\.html
  script: main.app

- url: /
 script: main.app


libraries:
- name: webapp2
  version: latest 

 - name: jinja2
  version: latest

And here is index.html contents:

<!DOCTYPE html>
<html>
<body>

<h1>External JavaScript</h1>

<p id="demo">A Paragraph.</p>

<button type="button" onclick="myFunction()">Try it</button>

<p><strong>Note:</strong> myFunction is stored in an external file called "myScript.js".</p>

<script src="../static/js/myScript.js"></script>

</body>
</html>

I hope you can help me find a solution, thanks in advance.

Your handler section:

handlers:

- url: /js
  static_dir: static/js

- url: /index\.html
  script: main.app

- url: /(.*)
  script: main.app

Now you can use in your index.html

<script src="/js/myScript.js"></script>

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