werkzeug

Build error with variables and url_for in Flask

痴心易碎 提交于 2019-12-18 04:35:20
问题 Have found one or two people on the interwebs with similar problems, but haven't seen a solution posted anywhere. I'm getting a build error from the code/template below, but can't figure out where the issue is or why it's occurring. It appears that the template isn't recognizing the function, but don't know why this would be occurring. Any help would be greatly appreciated - have been pounding my against the keyboard for two nights now. Function: @app.route('/viewproj/<proj>', methods=['GET',

How to make Flask/ keep Ajax HTTP connection alive?

爱⌒轻易说出口 提交于 2019-12-18 04:08:28
问题 I have a jQuery Ajax call, like so: $("#tags").keyup(function(event) { $.ajax({url: "/terms", type: "POST", contentType: "application/json", data: JSON.stringify({"prefix": $("#tags").val() }), dataType: "json", success: function(response) { display_terms(response.terms); }, }); I have a Flask method like so: @app.route("/terms", methods=["POST"]) def terms_by_prefix(): req = flask.request.json tlist = terms.find_by_prefix(req["prefix"]) return flask.jsonify({'terms': tlist}) tcpdump shows

X-Forwarded-Proto and Flask

瘦欲@ 提交于 2019-12-18 03:52:20
问题 I have precisely the same problem described in this SO question and answer. The answer to that question is a nice work around but I don't understand the fundamental problem. Terminating SSL at the load balancer and using HTTP between the load balancer and web/app servers is very common. What piece of the stack is not respecting the X-Forwarded-Proto? Is it werkzeug? Flask? uwsgi? In my case I'm using an AWS ELB (which sets X-Forwarded-Proto) => Nginx (which forwards along X-Forwarded-Proto to

How do I stream a file using werkzeug?

删除回忆录丶 提交于 2019-12-18 03:38:30
问题 I want to stream a big file via werkzeug. Currently my wsgi application looks like this: from werkzeug.wrappers import Request, Response from werkzeug.wsgi import ClosingIterator, wrap_file import os class Streamer(object): def __init__(self): pass def __call__(self, environ, start_response): request = Request(environ) filename = os.getcwd() + "/bigfile.xml" try: response = wrap_file(environ, open(filename) ) return response except HTTPException, e: response = e return ClosingIterator

How to set up autoreload with Flask+uWSGI?

ぐ巨炮叔叔 提交于 2019-12-17 23:20:36
问题 I am looking for something like uWSGI + django autoreload mode for Flask. 回答1: You could try using supervisord as a manager for your Uwsgi app. It also has a watch function that auto-reloads a process when a file or folder has been "touched"/modified. You will find a nice tutorial here: Flask+NginX+Uwsgi+Supervisord 回答2: I am running uwsgi version 1.9.5 and the option uwsgi --py-autoreload 1 works great 回答3: If you're configuring uwsgi with command arguments, pass --py-autoreload=1 : uwsgi -

Run python script as daemon at boot time (Ubuntu)

岁酱吖の 提交于 2019-12-17 21:56:58
问题 I've created small web server using werkzeug and I'm able to run it in usual python way with python my_server.py . Pages load, everything works fine. Now I want to start it when my pc boots. What's the easiest way to do that? I've been struggling with upstart but it doesn't seem to "live in a background" cuz after I execute start my_server I immediately receive kernel: [ 8799.793942] init: my_server main process (7274) terminated with status 1 my_server.py: ... if __name__ == '__main__': from

What's the right approach for calling functions after a flask app is run?

放肆的年华 提交于 2019-12-17 17:57:10
问题 I'm a little confused about how to do something that I thought would be quite simple. I have a simple app written using Flask . It looks something like this: from flask import Flask app = Flask(__name__) def _run_on_start(a_string): print "doing something important with %s" % a_string @app.route('/') def root(): return 'hello world' if __name__ == "__main__": if len(sys.argv) < 2: raise Exception("Must provide domain for application execution.") else: DOM = sys.argv[1] _run_on_start("%s" %

Flask URL Parameters with % Are Not Properly Handled

ⅰ亾dé卋堺 提交于 2019-12-13 08:38:28
问题 EDIT2: I apologize for the lack of clarity. I will provide several values. The first is the URL that I call using my frontend app. The second is the value before calling urllib.unquote . The third is the value after calling urlib.unquote . frontend: console.log('http://localhost:8080/v1/' + encodeURIComponent(name)) backend: def f(param=''): print('*', param) param = urllib.unquote(param) print('**', param) Ex. http://localhost:8080/v1/https%3A%2F%2Fgoogle.com * https:%2F%2Fgoogle.com **

expand werkzeug useragent class

 ̄綄美尐妖づ 提交于 2019-12-13 01:51:19
问题 I want to expand werkzeug UserAgent class with one more browser. How can I do it without modifying the source code of werkzeug library? I'm new in python so I have small idea about mixins, inheritance, modules and so on. I've found in docs: It’s a good idea to create a custom subclass of the BaseRequest and add missing functionality either via mixins or direct implementation. Here an example for such subclasses: from werkzeug.wrappers import BaseRequest, ETagRequestMixin class Request

How to measure memory usage of a web request when using Werkzeug/Flask?

旧巷老猫 提交于 2019-12-12 20:48:35
问题 Is there a way to measure the amount of memory allocated by an arbitrary web request in a Flask/Werkzeug app? By arbitrary, I mean I'd prefer a technique that lets me instrument code at a high enough level that I don't have to change it to test memory usage of different routes. If that's not possible but it's still possible to do this by wrapping individual requests with a little code, so be it. In a PHP app I wrote a while ago, I accomplished this by calling the memory_get_peak_usage()