pyramid

Pyramid: how to set cookie without renderer?

情到浓时终转凉″ 提交于 2019-12-08 16:15:21
问题 In configuration file: config.add_route('lang', '/lang-{code}') In views: @view_config(route_name='lang') def lang(request): code = request.matchdict['code'] response = Response() response.set_cookie('lang', value=code, max_age=31536000) # max_age = year return HTTPFound(location=request.environ['HTTP_REFERER']) The mechanism is simple: there is a dropped down menu item with languages and clicking on anyone must refresh site with new locale. Runs without errors, but no cookie set up... What I

Pyramid Framework - Can you call two seperate view functions to the same template

五迷三道 提交于 2019-12-08 14:42:29
I was playing around with the pyramid framework, and I was wondering if it is possible to call two view functions to the same template: so for example: def view1(request) args1 = 'a string' return render_to_response('page.mak',{'args1'=args1}, request=request) def view2(request) args2 = 'a string 2' return render_to_response('page.mak',{'args2'=args2}, request=request) So, note both are using the page.mak template. {'args1'=args1} is not valid Python. {'args1':args1} is though. Yes it is. Why do you suspect this would be a problem? Have you tried it and hit some error? 来源: https:/

uWSGI Fails with No module named encoding Error

孤街浪徒 提交于 2019-12-08 14:41:53
问题 I am trying to setup uWSGI with Pyramid, but I am getting this error, when attempting uwsgi --ini-paste development.ini Python version: 3.2.3 Error message: uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3 Python version: 3.2.3 (default, Oct 19 2012, 20:08:46) [GCC 4.6.3] Set PythonHome to /root/path/to/virtualenv Fatal Python error: Py_Initialize: Unable to get the locale encoding ImportError: No module named encodings Here is what I have in development.ini [uwsgi] socket = /tmp

Pyramid + ZODB Image storing

流过昼夜 提交于 2019-12-08 13:46:29
I have an upload form that accepts a zip file and has a method that unzips it and get each file from it. Make a unique id from the md5 hash of it and stores them in a dictionary; dict[uid] = imagebinary and returns it so that the form can store them into ZODB. I can't store the image just like that, as this error spits out; 2013-01-31 08:59:59,061 ERROR [waitress][Dummy-5] Exception when serving / Traceback (most recent call last): File "/home/maverick/inigo/sources/devenv/lib/python2.7/site-packages/waitress-0.8.2-py2.7.egg/waitress/channel.py", line 329, in service task.service() File "/home

What is a good way to organize your models, connections if one wants to use SQLAlchemy to connect several databases to various applications?

萝らか妹 提交于 2019-12-08 12:46:24
问题 Background: This is the situation I am facing and so far my current solution seems rather clunky. I want to improve on it. Right now: I setup connections to each database in the main function of the Pyramid application: def main(global_config, **settings): a_engine = engine_from_config(settings, 'A.') b_engine = engine_from_config(settings, 'B.') ASession.configure(bind=a_engine) BSession.configure(bind=b_engine) "ASession" and "BSession" are simply globally defined scoped_session in /models/

Sqlalchemy query returns incorrect and outdated results (for sqlite engine)

≡放荡痞女 提交于 2019-12-08 12:20:43
问题 I'm using sqlalchemy with sqlite engine (development server) and just discovered that after update query, queries in next web-requests return outdated data set (that depends on fact which thread is used for the request, as I understand there is a pool of threads). I'm using scoped_session and the other recommended stuff from docs ( DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) ). Here is the example of web requests and what's executed there. request-1:thread-1

Pyramid + ZODB Image storing

China☆狼群 提交于 2019-12-08 07:50:32
问题 I have an upload form that accepts a zip file and has a method that unzips it and get each file from it. Make a unique id from the md5 hash of it and stores them in a dictionary; dict[uid] = imagebinary and returns it so that the form can store them into ZODB. I can't store the image just like that, as this error spits out; 2013-01-31 08:59:59,061 ERROR [waitress][Dummy-5] Exception when serving / Traceback (most recent call last): File "/home/maverick/inigo/sources/devenv/lib/python2.7/site

Django idiosyncrasies

筅森魡賤 提交于 2019-12-08 07:32:17
问题 I recently started using Django 1.5.4 for a web app with MySQL backend. Just at the outset, I encountered certain limitations that makes me wonder is Django the right way to go ahead. Some glaring shortcomings are: Lack of composite primary keys. The bug has been open for 8 years. Isn't this bad for an app that relies on a lot of many-to-many tables to have a unnecessary auto primary key and work around with unique_together attribute. Reference: - http://comments.gmane.org/gmane.comp.python

Pyramid Framework - Can you call two seperate view functions to the same template

与世无争的帅哥 提交于 2019-12-08 06:34:06
问题 I was playing around with the pyramid framework, and I was wondering if it is possible to call two view functions to the same template: so for example: def view1(request) args1 = 'a string' return render_to_response('page.mak',{'args1'=args1}, request=request) def view2(request) args2 = 'a string 2' return render_to_response('page.mak',{'args2'=args2}, request=request) So, note both are using the page.mak template. 回答1: {'args1'=args1} is not valid Python. {'args1':args1} is though. 回答2: Yes

Pyramid postgresql connection

霸气de小男生 提交于 2019-12-08 05:06:48
问题 I am totally new to pyramid.I am trying to develop an application that will use both pyramid angd postgresql but i am totally confused about how to configure the initializedb.py file in the sripts directory especially initializing the database. I'm using PostgreSQL 9.1. 回答1: If I understand your question, you just need to find out where to configure the connection to DB. I assume you created a sqlAlchemy based project. In the root of the pyramid app you can find the ini files. By default you