-
Notifications
You must be signed in to change notification settings - Fork 0
1.2.2 Fungsi Routes dan Views
David Rigan edited this page Feb 11, 2020
·
2 revisions
Klien seperti web browser mengirim permintaan ke web server. Contoh, aplikasi Flask perlu mengetahui kode apa yang harus dijalankan untuk setiap URL yang diminta, sehingga ia menyimpan URL Fungsi python. Hubungan antara URL dan fungsi yang menanganinya disebut route.
Cara paling mudah untuk menentukan route dalam aplikasi Flask adalah melalui dekorator(@)app.route. Contoh seperti ini:
# app.py
@app.route('/')
def index():
return '<h1>Hello, World!</h1>'dan tambahkan code tersebut di app.py setelah app = Flask(__name__) sehingga source code lengkapnya terlihat seperti ini:
# app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return '<h1>Hello, World!</h1>'Referensi :
- Miguel Grinberg - Flask Web Development, Developing Web Applications with Python