webapp2

How to handle sensitive configuration information when deploying app-engine applications?

爷,独闯天下 提交于 2019-12-01 18:49:14
Example: I have an applications that needs to access an API providing an authentication token myApi = MyApi(token=my_private_sensible_token) I want to avoid having that private token in a configuration file that is part of the project. One solution that comes to mind is to isolate interaction with this service in a separate proxy application that is maintained by a restricted number of authorised people. App-engine allows to protect handlers with authentication and I could easily, in the proxy, allow only calls coming from an authorised app-engine consumer application. Different solutions I

Serve stylesheet with webapp2 outside of Google App Engine

≡放荡痞女 提交于 2019-12-01 05:35:01
问题 So I have successfully deployed an app using webapp2/jinja2 and a Paste server, but am having trouble serving static stylesheets. I have had luck accessing static files via this method, as well as implementing a StaticFileHandler I found with some google-fu: import os import mimetypes import webapp2 import logging class StaticFileHandler(webapp2.RequestHandler): def get(self, path): abs_path = os.path.abspath(os.path.join(self.app.config.get('webapp2_static.static_file_path', 'static'), path)

How can I send JSON-formatted cookie data using Python on Google App Engine?

六月ゝ 毕业季﹏ 提交于 2019-12-01 04:00:39
I'm trying to encode an object in a Python script and set it as a cookie so I can read it with client-side JavaScript. I've run into problems every way I've tried to do this. Generally, the cookie is formatted in a way that makes JSON.parse() break. My current script: cookie = Cookie.SimpleCookie() data = {"name": "Janet", "if_nasty": "Ms. Jackson"} cookie['test'] = json.dumps(data) self.response.headers.add_header("Set-Cookie", cookie.output(header='')) ... which results in test="{\"name\": \"janet\"\054 \"if_nasty\": \"Ms. Jackson\"}" on the client. I don't really want to introduce a hack-y

How can I send JSON-formatted cookie data using Python on Google App Engine?

核能气质少年 提交于 2019-12-01 02:15:06
问题 I'm trying to encode an object in a Python script and set it as a cookie so I can read it with client-side JavaScript. I've run into problems every way I've tried to do this. Generally, the cookie is formatted in a way that makes JSON.parse() break. My current script: cookie = Cookie.SimpleCookie() data = {"name": "Janet", "if_nasty": "Ms. Jackson"} cookie['test'] = json.dumps(data) self.response.headers.add_header("Set-Cookie", cookie.output(header='')) ... which results in test="{\"name\":

How to decide the language from cookies/headers/session in webapp2?

删除回忆录丶 提交于 2019-11-30 20:31:26
I'd like to take advantage of webapp2's new features for localization that also has locale-specific formatting for time and currency. Django has a good function called get_language_from_request that I made use of before I completely migrated to webapp2 and I now use the i18n from webapp2 instead and I can switch between localizations that I write with gettext and compile to files named messages.mo that my app can read and display. I've then identified and prioritized the following ways to get user's language: 1. HTTP GET eg. hl=pt-br for Brazilian Portuguese 2. HTTP SESSION variable I call

Allowing <br> tags with Google App Engine and Jinja2

社会主义新天地 提交于 2019-11-30 19:42:43
In my web app, the user can make blog posts. When I display the blog post, newlines aren't shown because I didn't replace the new lines with <br> tags. The problem is that I've turned autoescaping on in Jinja, so <br> tags are escaped. I don't want to temporarily disable autoescaping, I want to specifically allow <br> tags. How would I do this? I have another answer that I think is the best. Initially I was just displaying my variable post.content as-is, and the newlines weren't being preserved. None of the solutions here worked (well), and my pre solution was just a quick fix and had major

Allowing <br> tags with Google App Engine and Jinja2

百般思念 提交于 2019-11-30 16:57:23
问题 In my web app, the user can make blog posts. When I display the blog post, newlines aren't shown because I didn't replace the new lines with <br> tags. The problem is that I've turned autoescaping on in Jinja, so <br> tags are escaped. I don't want to temporarily disable autoescaping, I want to specifically allow <br> tags. How would I do this? 回答1: I have another answer that I think is the best. Initially I was just displaying my variable post.content as-is, and the newlines weren't being

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

筅森魡賤 提交于 2019-11-30 14:02:06
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'/', HomeHandler), webapp2.Route(r'/login', LoginHandler, schemes=['https'], name='login') ], debug=True) I have

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

只愿长相守 提交于 2019-11-30 08:57:27
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 within the handler class code. I wan't to be able to see what certain variables looked like in the

How to decide the language from cookies/headers/session in webapp2?

久未见 提交于 2019-11-30 04:53:22
问题 I'd like to take advantage of webapp2's new features for localization that also has locale-specific formatting for time and currency. Django has a good function called get_language_from_request that I made use of before I completely migrated to webapp2 and I now use the i18n from webapp2 instead and I can switch between localizations that I write with gettext and compile to files named messages.mo that my app can read and display. I've then identified and prioritized the following ways to get