នៅក្នុងកម្មវិធីគេហទំព័រដោយប្រើប្រាស់កញ្ចប់ Flask ដែលហៅថា ការភ្ជាប់ផ្លូវ (routing) គឺជាការភ្ជាប់អាស័យដ្ឋានទាំងឡាយ (URL) ទៅនឹងទំព័រ HTML ដែលនឹងត្រូវបង្កើតឡើង ដោយកូដជាភាសា Python ។ ហើយការភ្ជាប់ផ្លូវនេះ ត្រូវធ្វើឡើងតាមរយៈ decorator ដែលជា method ឈ្មោះ route() ។ ពិនិត្យកម្មវិធីខាងក្រោមនេះ៖
លើសពីនេះទៀត យើងក៏អាចភ្ជាប់ផ្លូវមានប៉ារ៉ាមែតទៅនឹង function និងឬ method ទាំងឡាយបានដូចគ្នាដែរ ដោយធ្វើដូចខាងក្រោមនេះ៖
#c:\flask\index.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Index Page'
@app.route('/hello')
def hello():
return 'Hello, World'
ជាលទ្ធផល នៅពេលកម្មវិធីខាងលើនេះដំណើរការ បើសិនជាមានការចុចចូលមើលទំព័រដើម ដែលមានអាស័យដ្ឋានជា http://localhost:5000/, function ឈ្មោះ index() នឹងត្រូវយកទៅប្រើជាស្វ័យប្រវត្តិ ដែលនឹងបណ្តាលអោយប្រយោគ "Index Page" ត្រូវសរសេរនៅលើផ្ទៃ browser ។ តែបើសិនជាមានការចុចចូលទៅកាន់ទំព័រដែលមានអាស័យដ្ខានជា http://localhost:5000/hello វិញ function ឈ្មោះ hello() នឺងត្រូវយកទៅប្រើ។
លើសពីនេះទៀត យើងក៏អាចភ្ជាប់ផ្លូវមានប៉ារ៉ាមែតទៅនឹង function និងឬ method ទាំងឡាយបានដូចគ្នាដែរ ដោយធ្វើដូចខាងក្រោមនេះ៖
#c:\flask\index.py
from flask import Flask
app = Flask(__name__)
from markupsafe import escape
@app.route('/user/<username>')
def show_user_profile(username):
# show the user profile for that user
return 'User %s' % escape(username)
@app.route('/post/<int:post_id>')
def show_post(post_id):
# show the post with the given id, the id is an integer
return 'Post %d' % post_id
@app.route('/path/<path:subpath>')
def show_subpath(subpath):
# show the subpath after /path/
return 'Subpath %s' % escape(subpath)
Converter types:
| string | (default) accepts any text without a slash |
| int | accepts positive integers |
| float | accepts positive floating point values |
| path | like string but also accepts slashes |
| uuid | accepts UUID strings |














