How to load a javascript or css file into a BottlePy template?

Viewed 18788

I am trying to return a html template with BottlePy. And this works fine. But if I insert a javascript file like this in my tpl-file:

<script type="text/javascript" src="js/main.js" charset="utf-8"></script>

I get an 404 error. (Failed to load resource: the server responded with a status of 404 (Not Found))

Does anyone know how to fix this problem?

Here is my script file:

from bottle import route, run, view

@route('/')
@view('index')
def index():
    return dict()
run(host='localhost', port=8080)

And that is the template file, located in "./views" subfolder.

<!DOCTYPE html>
<html lang="de">
    <head>
        <meta charset="utf-8" />
        <script type="text/javascript" src="js/main.js" charset="utf-8"></script>
    </head>
    <body>
    </body>
</html>

Maybe it is the "rootPath/js/main.js" from the development server where it looks for my js-file?

The structure of the files is:

app.py
-js
 main.js
-views
 index.tpl

Thanks.

3 Answers
Related