werkzeug

Changing values on a werkzeug request object

落花浮王杯 提交于 2019-12-25 07:39:10
问题 I have a request object that comes from werkzeug. I want to change a value on this request object. This is not possible because werkzeug request objects are immutable. I understand this design decision, but I need to change a value. How do I do this? >>> request <Request 'http://localhost:5000/new' [POST]> >>> request.method 'POST' >>> request.method = 'GET' *** AttributeError: read only property I tried doing a deepcopy , but the resulting copy is immutable also. I guess I could just create

import werkzeug VS from werkzeug import security

半城伤御伤魂 提交于 2019-12-24 13:27:41
问题 My current understanding (based on these answers: one, two, three; and Python documentation) of how import in Python works is (just in case it matters: all the code snippets are tested on Python 3.6.1) : Say we have a module mod , which has submodules sub and sub1 ; sub , in turn, has a function func ; then we can (given that mod installed in current environment, of course): import mod mod.sub.func() mod.sub1 # or import mod.sub mod.sub.func() mod.sub1 # will result in "NameError: name 'mod'

How to use Werkzeug interactive traceback debugger in a Django project hosted on Heroku?

走远了吗. 提交于 2019-12-24 03:29:46
问题 With django-extensions installed in your Django project, on a local machine you can use manage.py runserver_plus to have the very useful Werkzeug debugger active, so that the 500 error page lets you poke around with your stack interactively. How do you activate the Werkzeug-enabled 500 page when running from Heroku? 回答1: If you are using gunicorn to serve your Django application on Heroku like on their tutorial https://devcenter.heroku.com/articles/django, you will not be able to see the

Why isn't Flask giving me an interactive debugger?

笑着哭i 提交于 2019-12-23 13:53:52
问题 Here's a simple Flask app with a syntax error (it should be sys.version , not sys.version() from flask import Flask, url_for, request, render_template import sys app = Flask(__name__) app.config.from_object(__name__) @app.route('/') def index(): version = sys.version() return "This is the index page. Python version info: {}".format(version) if __name__ == '__main__': app.run(debug=True) When I run it locally and try to access http://localhost:5000, I get the nice Werkzeug debugger: but when I

in a Flask unit-test, how can I mock objects on the request-global `g` object?

给你一囗甜甜゛ 提交于 2019-12-20 18:35:23
问题 I have a flask application that is setting up a database connection in a before_filter , very similar to this: @app.before_request def before_request(): g.db = connect_db() Now: I am writing some unit-tests and I do not want them to hit the database. I want to replace g.db with a mock object that I can set expectations on. My tests are using app.test_client() , as is demonstrated in the flask documentation here. An example test looks something like def test(self): response = app.test_client()

in a Flask unit-test, how can I mock objects on the request-global `g` object?

北慕城南 提交于 2019-12-20 18:35:05
问题 I have a flask application that is setting up a database connection in a before_filter , very similar to this: @app.before_request def before_request(): g.db = connect_db() Now: I am writing some unit-tests and I do not want them to hit the database. I want to replace g.db with a mock object that I can set expectations on. My tests are using app.test_client() , as is demonstrated in the flask documentation here. An example test looks something like def test(self): response = app.test_client()

nginx + uwsgi + flask - disabling custom error pages

那年仲夏 提交于 2019-12-19 05:42:47
问题 Is it possible to disable nginx's custom error pages - if I may call them that - to display my framework's exception pages? I can't really see my werkzeug debugger tool rendered in html... UPDATE OK, I got to make a very very simple flask application to work and I'll post the bits: /home/my_user/.virtualenvs/nginx-test/etc/nginx.conf worker_processes 1; events { worker_connections 1024; } http { server { listen 5000; server_name localhost; access_log /home/my_user/.virtualenvs/nginx-test/lib

Parse X-Forwarded-For to get ip with werkzeug on Heroku

我怕爱的太早我们不能终老 提交于 2019-12-19 03:17:41
问题 Heroku proxies requests from a client to server, so you have to parse the X-Forwarded-For to find the originating IP address. The general format of the X-Forwarded-For is: X-Forwarded-For: client1, proxy1, proxy2 Using werkzeug on flask, I'm trying to come up with a solution in order to access the originating IP of the client. Does anyone know a good way to do this? Thank you! 回答1: Werkzeug (and Flask) store headers in an instance of werkzeug.datastructures.Headers. You should be able to do

Match an arbitrary path, or the empty string, without adding multiple Flask route decorators

吃可爱长大的小学妹 提交于 2019-12-18 08:59:03
问题 I want to capture all urls beginning with the prefix /stuff , so that the following examples match: /users , /users/ , and /users/604511/edit . Currently I write multiple rules to match everything. Is there a way to write one rule to match what I want? @blueprint.route('/users') @blueprint.route('/users/') @blueprint.route('/users/<path:path>') def users(path=None): return str(path) 回答1: It's reasonable to assign multiple rules to the same endpoint. That's the most straightforward solution.

Server is serving old versions of static files, but trimmed or padded to match length of new versions

坚强是说给别人听的谎言 提交于 2019-12-18 04:43:09
问题 The symptoms of my problem match this question pretty much exactly: Changed static files are cropped/padded to the new size and served the old - Fedora Whenever I make changes to my static files (e.g. .js and .css), those changes don't show up in the served file. However, if my changes cause the file to change length, then the served file does match the new length: If I delete characters from anywhere in the static file, then the served file is trimmed at the end by that many characters. If I