webapp2

PATCH method handler on Google AppEngine WebApp2

孤人 提交于 2019-12-05 17:44:24
问题 I tried to use a def patch(): method in my webapp2.RequestHandler to support partial resource updates, but then saw that the allowed methods are frozen in webapp2.py: allowed_methods = frozenset(('GET', 'POST', 'HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE')) How can I extend webapp2.RequestHandler or modify the WSGIApplication class to allow the PATCH HTTP method when deployed on Google AppEngine? 回答1: Just use a monkey patch by performing this before creating a WSGIApplication : allowed

webapp2 Route to match all other paths

纵然是瞬间 提交于 2019-12-05 12:33:07
I've the following code in my main app. I expect all paths other than the first two to be caught by the last route (/.*). But I get 404 error. What am I missing? import webapp2 from webapp2 import WSGIApplication, Route # ---- main handler class MainPage(webapp2.RequestHandler): def get(self): ret = jinja2render.DoRender(self) return ret routes = [ Route (r'/rpc', handler = 'rpc.RPCHandler'), Route (r'/secured/somesecuredpage', handler = 'secured.securedPageHandler'), Route (r'/.*', handler = MainPage), ] app = WSGIApplication(routes, debug=True) I can change the last route from "/. " to "/<:.

webapp2 - How to reverse URL in templates?

这一生的挚爱 提交于 2019-12-05 08:40:26
I'm starting with webapp2. My english is not very good, so i'll use an example to explain my problem: Suppose i'm building an application that will handle cars information. I've these handlers: ViewHandler: will display a view for a single car, with all of its information (engine, year, brand, model, etc..) ListHandler: will display all the cars in the application, with a link to the view page. The problem is that i can't build that link to the single view. I could do this in the template: <ul> <li><a href='/cars/view/{{car.id}}'>{{car.model}}</a></li> </ul> but don't like that (where's the

How to handle uploaded files in webapp2

☆樱花仙子☆ 提交于 2019-12-05 04:13:44
Google appengine's webapp2 has a very cryptic documentation regarding the handling of uploaded files . Uploaded files are available as cgi.FieldStorage (see the cgi module) instances directly in request.POST. I have a form which makes a POST request of JSON files which I want to store in an NDB.JsonProperty. Can anyone offer a short example of how do I read the file from the request object? You can use enctype="multipart/form-data" in your form, and then get file content by using in your handler: raw_file = self.request.get('field_name') Then, pass raw_file as input to your model's property.

Decoding JSON with python using Appengine

北城以北 提交于 2019-12-05 03:43:34
问题 I have the following code which retrieves values from a simple 3 input form: //retrieves data from a form var $form = $( this ), prgname= $form.find('input[name="prg"]').val(), startDate = $("#startdate").datepicker({ dateFormat: 'yy-mm-dd' }).val(), endDate = $("#enddate").datepicker({ dateFormat: 'yy-mm-dd' }).val(); The following code sends the request to the server: var request = $.ajax({ url: "/prg/", type: "post", data: JSON.stringify({prg: prgname, start:startDate, end:endDate}),

webapp2 with python3

徘徊边缘 提交于 2019-12-05 02:29:36
I use webapp2 with python 2.7 with or without googleAppEngine. I'm now trying to use it with Python 3.3 I've used PIP to install webapp2 Install run with success but when I try to import webapp2 from IDLE gaves me the folowing error: File "<pyshell#0>", line 1, in <module> import webapp2 File "C:\Python3\lib\webapp2.py", line 571 except Exception, e: ^ I suspect it's a thing that must be updated in order to work with Python3... ?anybody done this already or should I wait for an updated version of webapp2 ?is there any a beta version for Python 3 that we can access Indeed, webapp2 is not Python

GAE: Enabling Edge Cache with webapp2 (Python)

主宰稳场 提交于 2019-12-05 01:19:50
问题 There has been this new video on youtube demonstrating the strength of EdgeCaching in the GAE architecture, and at this particular point in the video they demonstrate how easy it is to leverage: http://www.youtube.com/watch?v=QJp6hmASstQ#t=11m12 Unfortunately it's not that easy... I'm looking to enable edge caching using the webapp2 framework provided by Google. I'm calling: self.response.pragma = 'Public' self.response.cache_expires(300) but it seems overridden by something else. The header

How to get uri_for with webapp2 in unit test?

这一生的挚爱 提交于 2019-12-05 01:18:36
I'm trying to unit test a handler with webapp2 and am running into what has to be just a stupid little error. I'd like to be able to use webapp2.uri_for in the test, but I can't seem to do that: def test_returns_200_on_home_page(self): response = main.app.get_response(webapp2.uri_for('index')) self.assertEqual(200, response.status_int) If I just do main.app.get_response('/') it works just fine. The exception received is: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 318, in run testMethod() File "tests.py", line

Simple Python and Ajax Example How to Send Response with Python?

ⅰ亾dé卋堺 提交于 2019-12-05 00:58:08
问题 I am testing out some code with Python and Javascript trying to get an Ajax system set up. Basically I just want to input a word and have the python code send it back. Here is my html/javascript: <html> <head> <title>Simple Ajax Example</title> <script language="Javascript"> function xmlhttpPost(strURL) { var xmlHttpReq = false; var self = this; // Mozilla/Safari/Chrome if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); } // IE else if (window.ActiveXObject) { self

How do I make a trailing slash optional with webapp2?

寵の児 提交于 2019-12-04 16:54:21
问题 I'm using the new webapp2 (now the default webapp in 1.6), and I haven't been able to figure out how to make the trailing slash optional in code like this: webapp.Route('/feed', handler = feed) I've tried /feed/? , /feed/* , /feed\/* and /feed\/? , all to no avail. 回答1: To avoid creating duplicate URL:s to the same page, you should use a RedirectRoute with strict_slash set to True to automatically redirect /feed/ to /feed, like this: from webapp2_extras.routes import RedirectRoute route =