Question

I'm using Bottle to make a simple web form and want to set the Selectize.js jquery plugin to a field so the user can set several values to that same field. Inside my form tag I have the following code:

<label>
    <span>Links :</span>
    <input type="text" id="input-tags" name="links">
</label>
<script>
$('#input-tags').selectize({
    persist: false,
    createOnBlur: true,
    create: true
});
</script>

And the following .js and .css inside the head tag:

<link href="/selectize.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/selectize.js"></script>

To deal with static files I have the following route in my .py script:

@get('/<filename:re:.*\.js>')
def javascripts(filename):
    return static_file(filename, root='static/js')

@get('/<filename:re:.*\.css>')
def stylesheets(filename):
    return static_file(filename, root='static/css')

My route to deal with static files seems to be working properly 'cause I've tested it with other jquery plugin that does not use explicit code within the html file.

On this one, the problem seems to be on the explicit script code bellow the label tag. I found some articles about dealing with JSON but couldn't make it work (I also don't know if that is the right way to go).

Was it helpful?

Solution

Well, my best option was to put that explicit javascript into a new javascript file and add its path to the html like:

<script type="text/javascript" src="/<script_path_here>"></script>

That way my functions that handles the static files on the .py would do their job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top