@route('/auth/login', method=['GET', 'POST']) def login(): if request.method == 'POST': username = request.POST.get("username", '') password = request.POST.get("password", '') if password == config.admin_pwd and username == config.admin_user: session = get_current_session() session['username'] = username return {'code': 0, 'msg': 'OK'} else: return {'code': -1, 'msg': '用户名或密码错误'} else: return template('auth/login.html', config=config, media_prefix=media_prefix) @route('/auth/logout') def logout(): session = get_current_session() del session['username'] return redirect(request.params.get('next') or '/') if __name__ == "__main__": from mole.mole import default_app from mole.sessions import SessionMiddleware app = SessionMiddleware(app=default_app(), cookie_key="457rxK3w54tkKiqkfqwfoiQS@kaJSFOo8h", no_datastore=True) run(app=app, host=config.host, port=config.port, reloader=config.debug)
# -*- coding: utf-8 -*- import mocrud #import crud_example import db from mole.mole import default_app #加入SessionMiddleware 中间件 from mole.sessions import SessionMiddleware app = SessionMiddleware(app=default_app(), cookie_key="457rxK8ytkKiqkfqwfoiQS@kaJSFOo8h", no_datastore=True) #运行服务 from mole import run if __name__ == "__main__": run(app=app, host='0.0.0.0', port=8081)
from mole.const import TEMPLATE_PATH TEMPLATE_PATH.append('./apps/templates/') # 配置静态目录 @route('/static/:file#.*#') def media(file): return static_file(file, root='./apps/media') @route('/media/:file#.*#') def media(file): return static_file(file, root='./apps/media') # 配置系统app COOKIE_KEY = '457rxK8ytkKiqkfqwfoiQS@kaJSFOo8h' from mole.mole import default_app app = default_app() # 安装公共路由视图 import routes #数据库接口配置 from DBUtils.PooledDB import PooledDB ############ Mysql ######## #import MySQLdb as pyDB #dbpool = PooledDB( # creator=MySQLdb, # maxusage=1000, # host='localhost', # user='******', # passwd='root', # db='db_name')
def _web_run(port = 8000): app = SessionMiddleware(app=default_app(), cookie_key="457rxK3w54tkKiqkfqwfoiQS@kaJSFOo8h",no_datastore=True) run(app=app, host='0.0.0.0', port = port, reloader = True);
import os sys.path.append('./lib') sys.path.append('../../../python-support') #os.environ["PYTHONPATH"]='../' set_lib_path() #安装的mosys、apps系统模块 import apps import mosys from mole.const import TEMPLATE_PATH TEMPLATE_PATH.append('./apps/templates/') TEMPLATE_PATH.append('./lib/mosys/templates/') #安装的PyRedisAdmin import PyRedisAdmin.routes import serverM.routes TEMPLATE_PATH.append('./lib/PyRedisAdmin/templates/') #加入SessionMiddleware 中间件 COOKIE_KEY = '457rxK8ytkKiqkfqwfoiQS@kaJSFOo8h' from mole.mole import default_app from mole.sessions import SessionMiddleware app = default_app() app = SessionMiddleware(app=app, cookie_key=COOKIE_KEY, no_datastore=True) #运行服务器 from mole import run if __name__ == "__main__": run(app=app, host='0.0.0.0', port=8123, reloader=True)
# coding=utf-8 from mole.mole import default_app application=default_app()