国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

web.py在SAE中的Session問題解決方法(使用mysql存儲)

2020-02-23 01:38:26
字體:
來源:轉載
供稿:網友

這段時間一直想嘗試著在SAE中使用Python,初步選擇了Web.py框架做為開發框架,但是可憐SAE上的資料少的可憐,有點問題基本上解決不了,今天解決一個Session在Session的存儲問題,在SAE中不能直接用本地文件存儲,好像是權限的原因,我現在采用的是保存在mysql中,效果也不錯。希望對大家有幫助。直接上代碼了。

index.wsgi

#!/usr/bin/env python# coding: utf-8import osimport webimport saefrom config.url import urlsfrom config import settings #是否具有調試功能web.config.debug = False# app = web.application(urls, globals()).wsgifunc()# application = sae.create_wsgi_app(app) #解決Session在SAE中的問題app = web.application(urls, globals()) #將session保存在數據庫中db = settings.dbstore = web.session.DBStore(db, 'sessions')#session = web.session.Session(app, store, initializer={'access_token': 'true'})session = web.session.Session(app, store)web.config._session = session application = sae.create_wsgi_app(app.wsgifunc())url.py#!/usr/bin/env python# coding: utf-8 pre_fix = 'controllers.' urls = (  '/',          pre_fix + 'todo.Index',  '/todo/new',      pre_fix + 'todo.New',  '/todo/(/d+)',     pre_fix + 'todo.View',  '/todo/(/d+)/edit',   pre_fix + 'todo.Edit',  '/todo/(/d+)/delete',  pre_fix + 'todo.Delete',  '/todo/(/d+)/finish',  pre_fix + 'todo.Finish',  '/todo/login', pre_fix + 'login.LoginUser',  '/todo/checkuser',pre_fix+'login.CheckUser',  '/todo/reset',pre_fix+'todo.reset',  '/todo/saveupload','mycontrollers.saveupload.SaveUpload')setting.py#!/usr/bin/env python# coding: utf-8import webimport sae.const#數據庫設定db = web.database(dbn='mysql', user=sae.const.MYSQL_USER, pw=sae.const.MYSQL_PASS, host=sae.const.MYSQL_HOST, port=3307, db=sae.const.MYSQL_DB)#模板設定render = web.template.render('templates/', cache=False) config = web.storage(  email='oooo@qq.com<script cf-hash="f9e31" type="text/javascript">/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */</script>',  site_name = '任務跟蹤',  site_desc = '',  static = '/static',) web.template.Template.globals['config'] = configweb.template.Template.globals['render'] = renderlogin.py#!/usr/bin/env python# coding: utf-8import webfrom config import settingsrender = settings.renderdef myloadhook():  global session  session = web.config._sessionclass LoginUser:  def GET(self):    return render.LoginUser()class CheckUser:  def POST(self):    #獲取Session相關信息    myloadhook()    #獲取表單信息    i = web.input()    username =i.get('txtUserName',None)    password=i.get('txtUserPass',None)    #從全局配置文件中得到session    session = web.config._session    if username == 'chu888' and password == 'chu888':      session.access_token = 'true'      raise web.seeother('/')    else:      session.access_token = 'false'      raise web.seeother('/todo/login')            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 搜索| 林口县| 旬阳县| 吉木萨尔县| 枣阳市| 长沙县| 武鸣县| 天台县| 兰坪| 石渠县| 孟津县| 达日县| 新乡市| 山西省| 洪洞县| 佛坪县| 措美县| 嘉祥县| 彰武县| 简阳市| 临清市| 道真| 新龙县| 家居| 梁山县| 金华市| 大新县| 寻甸| 长顺县| 永寿县| 江达县| 策勒县| 迭部县| 竹溪县| 游戏| 宁乡县| 天门市| 巧家县| 伊吾县| 昔阳县| 永吉县|