web.py session Problem Solving method in SAE (using MySQL storage)

Source: Internet
Author: User
This time has been trying to use Python in the SAE, the initial selection of the web.py framework as a development framework, but poor SAE on the poor data, a little problem basically can not solve, today solve a session in the session of the storage problem, In the SAE can not directly with the local file storage, as if the reason for the permissions, I now use is saved in MySQL, the effect is good. Hope to be of help to everyone. directly on the code.

Index.wsgi

#!/usr/bin/env python# coding:utf-8import osimport webimport saefrom config.url Import urlsfrom config import settings #是 No debug feature 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# database Set 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) # Template settings render = Web.template.render (' templates/', cache=false) config = web.storage (email= ' oooo@qq.com ', site_name = ' Task trace ', 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.rende Rdef 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) #从全The local configuration file gets 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/lo Gin ')
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.