This file contains hidden or 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
#!/usr/bin/env python | |
#-*- coding:utf8 -*- | |
from datetime import datetime | |
from sqlalchemy import create_engine | |
from sqlalchemy.orm import scoped_session, sessionmaker | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, Date | |
from sqlalchemy.dialects.mysql import TIMESTAMP | |
from sqlalchemy.types import TypeDecorator |
This file contains hidden or 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, abort | |
app = Flask('aplikasi pertama') | |
session_nya = {} | |
@app.route('/login') | |
def login(): | |
if not session_nya.get('user'): | |
session_nya['user'] = "arian" | |
return 'berhasil login' |
This file contains hidden or 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
if __name__ == '__main__': | |
app.run() |
This file contains hidden or 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
@app.route('/about') | |
def about(): | |
return "hello" |
This file contains hidden or 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
@app.route('/about/<username>') | |
def about(username): | |
return "hello " + username |
This file contains hidden or 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
@app.route('/about/<string:username>') | |
def about(username): | |
return "hello " + username |
This file contains hidden or 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
@app.route("/about/<username>/<kata>") | |
def kata(username, kata): | |
return kata + " " +username |
This file contains hidden or 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 abort | |
login = True | |
def check(func): | |
def cannot_access(): | |
abort(403, "kau tidak bisa masuk gan") | |
def inside(): | |
if not login: | |
cannot_access() |
This file contains hidden or 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
if app.config['ENV'] == 'production': | |
app.config.from_object(ConfigProduction) | |
else: | |
app.config.from_object(ConfigDevelopment) |
This file contains hidden or 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
class Confignya: | |
DEBUG = True, | |
PERMANENT_SESSION_LIFETIME = timedelta(days=2) | |
SECRET_KEY = "kodeacakdisini" | |
app.config.from_object(Confignya) |
NewerOlder