简体   繁体   中英

Import Javascript file in Bottle (framework jQuery)

I have a problem when I try to run my HTML file with javascript in Bottle. Have a look at my code:

bottle server:

from bottle import static_file
...
@route('/static/<filename>')
def static():
return static_file(filename, root='.')
...

HTML file:

...
<input type="text" id="time" class="datepicker" required>
...
<script type="text/javascript" src="static/jquery-ui/jquery-2.1.4.js"></script>
<script type="text/javascript" src="static/jquery-ui/jquery-ui.js"></script>
<link rel="stylesheet" href="static/jquery-ui/jquery-ui.css">
<script type="text/javascript" src="static/jquery-ui/my-script.js"></script>

Javascript file:

$(function() {
$('.datepicker').datepicker();
});

HTML file runs correctly when I don't use Bottle (so without using style/ ) but not from Bottle. I use a method static() to return the url of my javascript file, this method works for css file, but no result for javascript...

Instead of hard-coding the paths, I would suggest to use Bottle's get_url function.If you publish your application under a directory (fe domain.com/app) it won't work. So better use src="{{ get_url('static', filename='jquery-ui/jquery-2.1.4.js') }}"

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