Reputation: 1895
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.
Upvotes: 0
Views: 120
Reputation: 11706
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>
Upvotes: 2