1

I was right at the beginning to learn Flask and following the tutorial at http://flask.pocoo.org/docs/patterns/jquery/ . As the author said, it is usually a better idea to have the script in a separate script file.

But I didn't manage to find out how to do this. I just wrote:

<script type=text/javascript src='foo.js'></script>
<h1>jQuery Example</h1>
<p><input type=text size=5 name=a> +
<input type=text size=5 name=b> =
<span id=result>?</span>
<p><a href=# id=calculate>calculate server side</a>

and in the foo.js I simply copied the content of the first script of the original html code. However when I run the server I got nothing but a blank page, with the log file is "GET /foo.js HTTP/1.1" 304

I'm really a newbie at web programming and couldn't find out what was wrong. Thank you guys !

1 Answer 1

4

As shown in the loading jQuery section, you need to use the url_for() helper to get the proper location to your script.

<script type="text/javascript" src="{{ url_for('static', filename = 'foo.js') }}"></script>

Something along the lines of the above should work. I have a feeling you may have other issues with the script but the server shouldn't have any more problems finding it.

If it does, please post how you have your directory structure setup.

Sign up to request clarification or add additional context in comments.

1 Comment

thx, I found out finally that it has something to do with the javascript I wrote. A silly mistake. :-( Thank u again for telling me about the url_for staff, havn't read about that carefully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.