Skip to content

Instantly share code, notes, and snippets.

View Rhyanz46's full-sized avatar
🏠
Working from home

Arian Saputra Rhyanz46

🏠
Working from home
View GitHub Profile
@Rhyanz46
Rhyanz46 / python-sqlalchemy-timezone
Created May 5, 2020 14:50 — forked from tell-k/python-sqlalchemy-timezone
sqlalchemy timzone datetime
#!/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
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'
if __name__ == '__main__':
app.run()
@app.route('/about')
def about():
return "hello"
@app.route('/about/<username>')
def about(username):
return "hello " + username
@app.route('/about/<string:username>')
def about(username):
return "hello " + username
@app.route("/about/<username>/<kata>")
def kata(username, kata):
return kata + " " +username
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()
if app.config['ENV'] == 'production':
app.config.from_object(ConfigProduction)
else:
app.config.from_object(ConfigDevelopment)
class Confignya:
DEBUG = True,
PERMANENT_SESSION_LIFETIME = timedelta(days=2)
SECRET_KEY = "kodeacakdisini"
app.config.from_object(Confignya)