How to solve the Session problem of web. py in SAE (using mysql storage)

Source: Internet
Author: User
This article mainly Introduces web. solve the Session problem of py in SAE (using mysql storage). This article provides the implementation code directly. the code contains detailed comments, if you want to use Python in SAE, you can refer to this period of time. the py framework is used as a development framework. However, there is little information on the SAE, and a problem is basically not solved. Today, the Session storage problem is solved, in SAE, local file storage cannot be used directly. it seems to be the reason for permission. I am using mysql to save it, and the effect is good. I hope to help you. Code directly.

Index. wsgi

#! /Usr/bin/env python # coding: utf-8import osimport webimport saefrom config. url import urlsfrom config import settings # whether the web Debugging function is available. config. debug = False # app = web. application (urls, globals ()). wsgifunc () # application = sae. create_wsgi_app (app) # solve the problem of Session in SAE app = web. application (urls, globals () # save the session in the database db = settings. dbstore = web. session. DBStore (db, 'session') # session = web. session. ses Sion (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', '/ Do/reset ', pre_fix + 'Todo. reset','/todo/saveupload ', 'mycontrollers. saveupload. saveupload') setting. py #! /Usr/bin/env python # coding: utf-8import webimport sae. const # database configuration 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 setting render = web. template. render ('Templates/', cache = False) config = web. storage (email = 'Oooo @ qq.com

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.