pyramid

How do I integrate a Bokeh Server into a Pyramids Application?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 21:29:48
In order of complexity, with Pyramids, I can create static bokeh graphs and then incorperate them with div tags like outlined here . The Bokeh documentations explain clearly how one can setup a bokeh server for interactive data exploration, and I have successfully created such an application. What I would like to do though is to have an interactive graph within a Pyramids view page. The requirements of this page would be as followed: Upon loading of the view, a bokeh server is somehow started, and the data is loaded into the server's object model. Somehow the Pyramid view will also receive the

Determine the user language in Pyramid

北慕城南 提交于 2019-12-03 16:23:48
问题 I want to make internationalization for my project. I followed how it is described in official documentation, but localization still doesn't work. Here is how I try get user locale: def get_locale_name(request): """ Return the :term:`locale name` associated with the current request (possibly cached).""" locale_name = getattr(request, 'locale_name', None) if locale_name is None: locale_name = negotiate_locale_name(request) request.locale_name = locale_name return locale_name But request doesn

The best way to store a python list to a database?

ε祈祈猫儿з 提交于 2019-12-03 15:03:34
问题 What would be the best way of storing a python list of numbers (such as [4, 7, 10, 39, 91]) to a database? I am using the Pyramid framework with SQLAlchemy to communicate to a database. Thanks! 回答1: Well conceptually you can store a list as a bunch of rows in a table using a one-to-many relation, or you can focus on how to store a list in a particular database backend. For example postgres can store an array in a particular cell using the sqlalchemy.dialects.postgres.ARRAY data type which can

Routes with trailing slashes in Pyramid

别说谁变了你拦得住时间么 提交于 2019-12-03 13:54:30
Let's say I have a route '/foo/bar/baz'. I would also like to have another view corresponding to '/foo' or '/foo/'. But I don't want to systematically append trailing slashes for other routes, only for /foo and a few others (/buz but not /biz) From what I saw I cannot simply define two routes with the same route_name. I currently do this: config.add_route('foo', '/foo') config.add_route('foo_slash', '/foo/') config.add_view(lambda _,__: HTTPFound('/foo'), route_name='foo_slash') Is there something more elegant in Pyramid to do this ? Found this solution when I was looking for the same thing

Non-ASCII character '\\x90' executing pserve on windows inside virtualenv

拟墨画扇 提交于 2019-12-03 13:18:05
Question: How can i solve no-ascii character error executing pserve on virtualenv in windows? Description: I'm trying to execute pserve (pyllons/pyramid development web server) inside a virtualenv on windows. It's a fresh install, so maybe it is related to versions. Problem: With the virtualenv activated, execute pserve config.ini throw error: SyntaxError: Non-ASCII character '\x90' in file C:\PATH_TO_MY_ENV_HOME\env\Scripts\pserve.exe on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details . Command line: pserve development.ini --reload Notes: this error

SQLAlchemy session issues with celery

耗尽温柔 提交于 2019-12-03 12:45:41
问题 I have scheduled a few recurring tasks with celery beat for our web app The app itself is build using pyramid web framework. Using the zopetransaction extension to manage session In celery, I am using the app as a library. I am redefining session in models with a function. It works well but once in a while, it raises InvalidRequestError: This session is in 'prepared' state; no further SQL can be emitted within this transaction I am not sure what is wrong and why it issues these warnings.

In the Pyramid web framework, how do I source sensitive settings into development.ini / production.ini from an external file?

北城以北 提交于 2019-12-03 11:44:56
问题 I'd like to keep development.ini and production.ini under version control, but for security reason would not want the sqlalchemy.url connection string to be stored, as this would contain the username and password used for the database connection. What's the canonical way, in Pyramid, of sourcing this setting from an additional external file? Edit In addition to solution using the environment variable, I came up with this solution after asking around on #pyramid: def main(global_config, *

Jinja2 Inheritance with Blocks and Includes

我怕爱的太早我们不能终老 提交于 2019-12-03 11:19:36
问题 I can't figure out how to modify blocks from included templates using Jinja2. Here's an example where I use three files. base.html: <html>{% include "content.html" %}</html> content.html: <h1>{% block title %}Title{% endblock title%}</h1> <div>{% block content_body %}Content Body{% endblock content_body%}</div> story.html {% extends "base.html" %} {% block title %}story.title{% endblock title %} {% block content_body %}story.description{% endblock content_body %} When rendering story.html, I

Pyramids route_url with additional query arguments

十年热恋 提交于 2019-12-03 10:43:25
In Pyramids framework, functions route_path and route_url are used to generate urls from routes configuration. So, if I have route: config.add_route('idea', 'ideas/{idea}') I am able to generate the url for it using request.route_url('idea', idea="great"); However, sometimes I may want to add additional get parameters to generate url like: idea/great?sort=asc How to do this? I have tried request.route_url('idea', idea='great', sort='asc') But that didn't work. Samuel Hapak You can add additional query arguments to url passing the _query dictionary request.route_url('idea', idea='great', _query

Using a different schema for the same declarative Base in sqlalchemy

瘦欲@ 提交于 2019-12-03 10:19:59
问题 I am new to both Pyramid and SQLAlchemy. I am working on a Python Pyramid project with SQLAlchemy. I have a simple model set up below. How would I go about being able to use this with different schemas at run-time? This will be a PostgreSQL database backend. Right now, "public" is hard-coded into the declarative base model. I would need the ability to use this same model with different schema. What is the best approach? Unless I missed it, the documentation at SQLAlchemy seemed unclear to me.