webapp2

webapp2 + jinja2: How can i get uri_for() working in jinja2-views

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 23:09:49
How can i add pass Model-Specific urls to the Template. Let's say, i want to build an edit-link. I would guess, using the uri_for() function would be an easy approach. But the following gives me "UndefinedError: 'webapp2' is undefined" {% webapp2.uri_for("editGreeting", greeting.key().id()) %} Or should i prepare these in the MainPage-Request-Handler? If so, i don't know how to add them to each greeting. The following Code-Example is taken from: http://webapp-improved.appspot.com/tutorials/gettingstarted/templates.html Controller/Handler class MainPage(webapp2.RequestHandler): def get(self):

How to use WSGI to reroute a user from http to https

别说谁变了你拦得住时间么 提交于 2019-11-29 19:55:24
问题 Original Question App Engine SDK 1.6.5 Python 2.7 webapp2 I have implemented webapp2 schemes to secure pages to https. The issue is that when a user goes to say http:// site/login instead of https:// site/login they get a 404 error due to the schemes not recognising the route. example main.py # Libraries import webapp2 # Local Controllers from controllers.HomeHandler import HomeHandler from controllers.LoginHandler import LoginHandler app = webapp2.WSGIApplication([ webapp2.Route(r'/',

How can I handle static files with Python webapp2 in Heroku?

一笑奈何 提交于 2019-11-29 14:19:07
I am now migrating my small Google App Engine app to Heroku platform. I don't actually use Bigtable, and webapp2 reduces my migration costs a lot. Now I'm stuck on handling the static files. Is there any good practices? If so, lead me there please. Thanks in advance. EDIT Well, I'm now using paste for my WSGI server. And paste.StaticURLParser() should be what I need to implement static file handler. However I have no idea how to integrate it with webapp2.WSGIApplication() . Could anyone help me? Maybe I need to override webapp2.RequestHandler class to load paste.StaticURLParser() properly;

how to unittest the template variables passed to jinja2 template from webapp2 request handler

放肆的年华 提交于 2019-11-29 12:58:34
问题 I've never done unit testing before. I want to master it. I'm trying to test my webapp2 handlers. To do this, I thought it would be a good idea to send a request to the handler e.g.: request = webapp2.Request.blank('/') # Get a response for that request. response = request.get_response(main.app) The problem is, response is mostly just a bunch of HTML etc. I want to look at what was passed to my jinja2 template from the handler before it was turned into HTML. I want my test to get at the state

Issue with sending XML to Web Api via http Post request

帅比萌擦擦* 提交于 2019-11-29 11:47:38
I would like to send the following XML document to my Web Api 2 controller; however, the [FromBody] parameter is always null. Here is the request XML body: <razorInbound server="PortfolioExposureServer" request="lookupRiskPointRecord"> <caller>RazorClient</caller> <responseMode>xml</responseMode> <body> <conditions> <fromOffset>0</fromOffset> <top>100</top> <condition> <keyPath> <keyElement nodeOffset='1'>Currency</keyElement> <keyElement nodeOffset='2'>ID</keyElement> </keyPath> <lookupValue>USD</lookupValue> </condition> </conditions> </body> </razorInbound> Using Postman to send the request

Uploading Files in webapp2/GAE

别说谁变了你拦得住时间么 提交于 2019-11-29 11:29:21
I need to upload and process a CSV file from a form in a Google App Engine application based on Webapp2 (Python) I understand I could use blobstore to temporary store the file but I am curious to know if there is a way to process the file without having to store it at all. The content of uploaded files is in self.request.POST in your handler, so you can get that content (assuming e.g the field for the uploaded file is named 'foo' ) with e.g content = self.request.POST.multi['foo'].file.read() So now you have the content as a string -- process it as you wish. This does of course assume the

Python App Engine webapp2 slow to route

你离开我真会死。 提交于 2019-11-29 08:08:07
I have a Python App Engine application which serves about 3M requests per day. I am trying to optimize the app to save on my ridiculously ballooned hosting bill. November, App Engine Frontend Instances: 12924.391 Hours, $604.22 I have the request handling down to some memcached calls, but now I've noticed that it usually takes about 20ms, sometimes as long as 166ms before webapp2 even passes the request to me. In the image below you can see a Trace showing "Post" happening at 166ms. Here is the code serving this. import logging logging.info("main.py logging imported") from imports import *

Maintain uniqueness of a property in the NDB database

China☆狼群 提交于 2019-11-29 01:45:35
An NDB model contains two properties: email and password . How to avoid adding to the database two records with the same email ? NDB doesn't have UNIQUE option for a property, like relational databases do. Checking that new email is not in the database before adding—won't satisfy me, because two parallel processes can both simultaneously do the checking and each add the same email . I'm not sure that transactions can help here, I am under this impression after reading some of the manuals. Maybe the synchronous transactions ? Does it mean one at a time? Create the key of the entity by email,

webapp2 + jinja2: How can i get uri_for() working in jinja2-views

风流意气都作罢 提交于 2019-11-28 20:25:06
问题 How can i add pass Model-Specific urls to the Template. Let's say, i want to build an edit-link. I would guess, using the uri_for() function would be an easy approach. But the following gives me "UndefinedError: 'webapp2' is undefined" {% webapp2.uri_for("editGreeting", greeting.key().id()) %} Or should i prepare these in the MainPage-Request-Handler? If so, i don't know how to add them to each greeting. The following Code-Example is taken from: http://webapp-improved.appspot.com/tutorials

How to zip or tar a static folder without writing anything to the filesystem in python?

送分小仙女□ 提交于 2019-11-28 14:37:25
I know about this question . But you can’t write to filesystem in app engine (shutil or zipfile require creating files) . So basically I need to archive something like /base/nacl using zip or tar, and write the output to the web browser asking the page (the output will never exceed 32 Mb) . It just happened that I had to solve the exact same problem tonight :) This worked for me: import StringIO import tarfile fd = StringIO.StringIO() with tarfile.open(mode="w:gz", fileobj=fd) as tgz: tgz.add('dir_to_download') self.response.headers['Content-Type'] ='application/octet-stream' self.response