Rental Bicycle App: Route to Static File

នៅ​ក្នុង​កម្មវិធី​គេហទំព័រ ដោយ​ប្រើប្រាស់​កញ្ចប់ Bottle ការធ្វើ​ផ្លូវ​ចូល​ទៅ​កាន់​ឯកសារ static ទាំងឡាយ ត្រូវ​ធ្វើ​ឡើង​ដូច​ខាង​ក្រោម​នេះ៖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#\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')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!--\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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#\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)