Last active
July 28, 2016 12:42
-
-
Save sinar96/c5901c23d9da3f44a197b9da656bbfb7 to your computer and use it in GitHub Desktop.
Code ini akan membantu kalian untuk memahami perbedaan code pada Static Route dan Dynamic route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
#create the application object | |
app = Flask(__name__) | |
app.config.from_object('config') | |
database.init_app(app) | |
@app.route("/") | |
def main(): | |
# Static Route | |
main = Main.query.all() | |
return render_template("main.html", **locals()) | |
@app.route("/<int:id>") | |
def show_content(id): | |
# Dynamic Route | |
main = Main.query.get(id) | |
if not main: | |
abort(404) | |
return render_template("mainpost.html", **locals()) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment