web.py

Web app starts many times - web.py

久未见 提交于 2019-12-11 14:06:51
问题 I have this code where it loads necessary files and prints necessary information when the server starts but inside if __name__ == "__main__": I'm starting a background process as well then finally app.run() is executed. My problem is after loading all and comes to the starting of background process it starts to print and load everything from beginning again. And also it does the same when the server get its first request (GET/POST). How can I make it load only once? import web from

Python 2.7 with Webpy - flup or modwsgi?

南笙酒味 提交于 2019-12-11 04:50:01
问题 I am unsure which of the two I should go for. Flup or modwsgi. Flup seems to have very little documentation and even less people adding to the code. modwsgi on the other hand seems to be widely supported. I just want to start running my webpy environmental so that I can utilize Python scripts online. But this thing stops me from moving ahead. Any suggestions? 回答1: My understanding is that flup 's author has discontinued development, but that's at best a rumor (someone please correct me!). I

web.py shared variables

家住魔仙堡 提交于 2019-12-10 16:12:51
问题 In web.py i need to create a shared variable, for which multiple threads(requests) can read or write to that variable. What is the preferred way, for this kind of a situation. thanks. 回答1: I'm not sure this is really a web.py question, but we do this sort of thing all the time for process-wide caches (that is, dict caches that are shared by all request threads). We use web.py, but my example below should apply to any multi-threaded Python web server. hotels.py: cache = {} def load_cache(): ""

jQuery/AJAX call with a timer

回眸只為那壹抹淺笑 提交于 2019-12-10 14:16:27
问题 How can i implement the below code with jQuery/AJAX timer,(I have created 2 URL classes by using web.py.Here 1st URL will return a random number between 1 and 250.I have created an AJAX call in the 2nd URL,so that when you hit the button ,AJAX will call the values from the 1st URL and it will display inside the text box),Now i just want to modify the code like during every 5 seconds AJAX should call the numbers from 1st URL and it should display inside the text box.Is there any way to solve

Python server “Aborted (Core dumped)”

谁说我不能喝 提交于 2019-12-10 12:53:35
问题 I use web.py to create a Python web server. This server is called to solve linear programming problems, and it uses the library CBC to do that. Every once in a while, the server crashes with a log that looks like that: 78.243.184.3:56271 - - [03/Jun/2016 04:35:54] "HTTP/1.1 GET /optimization" - 200 OK Aborted (core dumped) I belive "Aborted (core dumped)" is a C error, so it comes from either web.py or CBC. Is there any way to trace back the source of the error? 回答1: A core dump is caused by

How to obtain JSON value from Post in a web.py server app?

守給你的承諾、 提交于 2019-12-10 10:15:13
问题 Am using Python 2.7.6 along with web.py server to experiment with some simple Rest calls... Wish to send a JSON payload to my server and then print the value of the payload... Sample payload {"name":"Joe"} Here's my python script #!/usr/bin/env python import web import json urls = ( '/hello/', 'index' ) class index: def POST(self): # How to obtain the name key and then print the value? print "Hello " + value + "!" if __name__ == '__main__': app = web.application(urls, globals()) app.run()

Webpy sessions: AttributeError: 'ThreadedDict' object has no attribute 'username'

女生的网名这么多〃 提交于 2019-12-08 07:39:18
问题 I am making a webapp in python using web.py, I have set up the tables and can login the user and everything, but the initializer for sessions doesn't seem to work. I have the following in my code: store = web.session.DBStore(db, 'sessions') session = web.session.Session(app, store, initializer={'logged_in': 0, 'username': ''}) render = web.template.render('templates/', base='base', globals={'session': session, 'username': session.username}) But this throws the error: AttributeError:

HTTP POST Response Fails Using Web.py

Deadly 提交于 2019-12-08 05:06:06
问题 I suppose it goes without saying that I'm baffled by the following. This is a faux-continuation of my queries here: HTTP 303 (SeeOther): GET Works, POST Fails I'm posting another question because the other deals primarily with HTTP redirections, and does not address what I now believe to be the underlying problem. I have a very simple web.py class: class user: def GET(self, id): """List a single user""" web.header('Cache-control', 'no-cache') return 'wtf!!' def POST(self, id): """Save an

How to keep a variable value across requests in web.py

安稳与你 提交于 2019-12-08 04:05:22
问题 I want to update logfile as soon as a request comes. I have a class variable event_logging_enabled which is initialised to TRUE. and in the POST() function I check the value of event_logging_enabled. Now at run time, I modify the value of this flag to FALSE for subsequent requests. But It remains TRUE. During debugging, I found that when a request is received, a new object get created to handle each request, so, will pick initialized value i.e.TRUE. This is not the case for other functions

How to initialize session data in automated test? (python 2.7, webpy, nosetests)

守給你的承諾、 提交于 2019-12-08 03:13:51
问题 I have a web application that uses session data to determine what to do next. The application is running in the browser and does what it shall do. I'd like to write an automated test to have that knowledge for future projects. The last hours I failed miserable to initialize (and hand over) session data within my test. Also I couldn't find the answer for such a basic case on the web. However, here is the app code: import web from project import code urls = ( "/page", "/Page", "/", "Index" )