នៅក្នុងកម្មវិធីគេហទំព័រ ដោយប្រើប្រាស់កញ្ចប់ Bottle ការធ្វើផ្លូវចូលទៅកាន់ឯកសារ static ទាំងឡាយ ត្រូវធ្វើឡើងដូចខាងក្រោមនេះ៖
#\public\setup.py from bottle import route, static_file @route('/static/scripts/<filename>') def server_static(filename): return static_file(filename, root='./public/js') @route('/static/styles/<filename>') def server_static(filename): return static_file(filename, root='./public/css') @route('/static/images/<filename>') def server_static(filename): return static_file(filename, root='./public/images') @route('/static/fonts/<filename>') def server_static(filename): return static_file(filename, root='./public/fonts')
<!--\views\index.tpl--> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>{{data['site_title']}}</title> <script src="/static/scripts/main.js"></script> <link href="/static/styles/main.css" rel="stylesheet"></link> <link href="/static/images/site_logo.png" rel="icon" ></link> <link href="/static/fonts/setup.css" rel="stylesheet"></link> </head> <body> <h1>{{data['message']}}</h1> </body> </html>
#\app.py import os from bottle import route, run from controllers import index from public import setup @route('/') def main(): kargs = {"site_title":"Rental Bicycle App", "message":"កម្មវិធីគេហទំព័រ!"} return index.render(**kargs) if 'DYNO' in os.environ: run(host='0.0.0.0', port=os.environ.get('PORT', 9000)) else: run(host='localhost', port=9000, debug=True, reloader=True)