I'm using Google App Engine SDK for Python. When I write Javascript functions in a separate .js file and include it in the .py file, I get the following errors in Chrome:-
In .py file:-
Uncaught reference error: initFunc is not defined.
In .js file:-
Uncaught syntax error: Unexpected token <
Resource interpreted as script but transferred with MIME type text/html.
Source codes:-
.py file
print 'Content-Type: text/html'
print ''
print '\
<head>\
<title>Page</title>\
<script type="text/javascript" src="script.js">\
</script>\
</head>\
<body>\
<input type="button" onclick="initFunc();" value="Test" />\
</body>\
'
.js file
function initFunc(){alert("hi");}\
All the errors disappear when I include the initFunc in the .py file itself.
\on the first line of your multi-line string. You also have an unquoted<br>in python code, unless that's an attempt to format your code for SO and not actually in your code. You almost certainly want to use a WSGI framework and template system rather thanprinting HTTP headers and raw HTML, anyway.