pylons

Converting \n to <br> in mako files

梦想与她 提交于 2021-01-27 06:56:47
问题 I'm using python with pylons I want to display the saved data from a textarea in a mako file with new lines formatted correctly for display Is this the best way of doing it? > ${c.info['about_me'].replace("\n", "<br />") | n} 回答1: The problem with your solution is that you bypass the string escaping, which can lead to security issues. Here is my solution : <%! import markupsafe %> ${text.replace('\n', markupsafe.Markup('<br />'))} or, if you want to use it more than once : <%! import

Python - SqlAlchemy: Filter query by great circle distance?

安稳与你 提交于 2020-12-25 05:19:57
问题 I am using Python and Sqlalchemy to store latitude and longitude values in a Sqlite database. I have created a hybrid method for my Location object, @hybrid_method def great_circle_distance(self, other): """ Tries to calculate the great circle distance between the two locations If it succeeds, it will return the great-circle distance multiplied by 3959, which calculates the distance in miles. If it cannot, it will return None. """ return math.acos( self.cos_rad_lat * other.cos_rad_lat * math

What is this ZopeTransactionEvents error with SQLAlchemy while updating a Pyramid application?

南笙酒味 提交于 2020-12-15 05:30:27
问题 I'm updating Pyramid/SQLAlchemy legacy code to Python 3.8 from an app working fine under Python 2.7, and running it locally. All the necessary requirements are pip installed and setup.py runs without error. On running initialise with my local .ini file, All goes well, the database tables (MariaDB) are all written. in models.py from sqlalchemy.orm import ( scoped_session, sessionmaker, relationship, backref, synonym, ) from zope.sqlalchemy import ZopeTransactionEvents #[...] DBSession = scoped

How can I set a custom response header for pylons static (public) files?

白昼怎懂夜的黑 提交于 2020-01-20 06:54:26
问题 How do I add a custom header to files pylons is serving from public? 回答1: a) Let your webserver serve files from /public instead of paster and configure it to pass some special headers. b) Add a special route and serve the files yourself ala class FilesController(BaseController): def download(self, path) fapp = FileApp( path, headers=self.get_headers(path) ) return fapp(request.environ, self.start_response) c) maybe there is a way to overwrite headers and i just dont know how. 回答2: With a

Pylons FormEncode @validate decorator pass parameters into re-render action

自作多情 提交于 2020-01-14 04:15:29
问题 I am attempting to use the validate decorator in Pylons with FormEncode and I have encountered an issue. I am attempting to validate a form on a controller action that requires parameters, and if the validation fails, the parameters aren't passed back in when the form is re-rendered. Here's an example. def question_set(self, id): c.question_set = meta.Session.query(QuestionSet).filter_by(id=id).first() c.question_subjects = meta.Session.query(QuestionSubject).order_by(QuestionSubject.name)

Disable browser caching in pylons

空扰寡人 提交于 2020-01-13 19:36:50
问题 I'm have an action /json that returns json from the server. Unfortunately in IE, the browser likes to cache this json. How can I make it so that this action doesn't cache? 回答1: Make sure your responses are not telling the browser that the content expires in the future. There are two HTTP headers the control this. Expires Cache-Control - There are many possible values for this header, but the one that controls expiration is max-age=foo. In addition, IE may be revalidating. This means that IE

Disable browser caching in pylons

我与影子孤独终老i 提交于 2020-01-13 19:36:26
问题 I'm have an action /json that returns json from the server. Unfortunately in IE, the browser likes to cache this json. How can I make it so that this action doesn't cache? 回答1: Make sure your responses are not telling the browser that the content expires in the future. There are two HTTP headers the control this. Expires Cache-Control - There are many possible values for this header, but the one that controls expiration is max-age=foo. In addition, IE may be revalidating. This means that IE

pylons mako how to check if variable exist or not

时光怂恿深爱的人放手 提交于 2020-01-11 08:38:07
问题 In django, we can do this: views.py : def A(request): context = {test : 'test'} return render_to_response('index.html', context , context_instance = RequestContext(request)) def B(request): context = {} return render_to_response('index.html', context , context_instance = RequestContext(request)) index.html: {% if test %} {{ test }} {% endif %} And have our template render without error, even if i use method B , where variable 'test' does not exist, but I still can put it in the template. I

Pylons - url.current() incorrect, for '/test' shows '/test/test'?

懵懂的女人 提交于 2020-01-03 04:34:10
问题 I've got a pylons setup, using flup with nginx, and url.current() always returns totally wrong. I have a route: map.connect('testpage', '/test', controller='Main', action='test') And in that controller, I do url.current() and I get /test/test' instead of '/test'. I've tried changing SCRIPT_NAME` as various posts about using uwsgi suggest, but it makes no difference here. Any suggestions? 回答1: Actually it looks like I solved this. Apparently you have to set SCRIPT_NAME to '' AND restart the

How to check what permission failed in authorization in pyramid (pylons 2)?

自闭症网瘾萝莉.ら 提交于 2020-01-02 13:26:17
问题 I add a view for the forbidden view: from pyramid.exceptions import Forbidden config.add_view(forbidden_view, context=Forbidden) which redirects to a log in screen. But now i added some admin things which needed admin access, and I want to just show a "you don't have the permission" screen, how do I check for that in the forbidden view? 回答1: I'm afraid that information is lost when Pyramid raises a Forbidden error as the result of a permission denial. There's an item in the TODO.txt to carry