cherrypy

Download docxtpl generated file with cherrypy

痞子三分冷 提交于 2019-12-08 13:46:42
问题 I am using docxtpl to generate a word document, and wondering how a user can download this file once generated using cherrypy, please see my code below. the only solution i could come up with is to save it to the www folder and create a link to the location, but i am sure this can be simplified. code: import os, os.path import random import string import cherrypy from docxtpl import DocxTemplate import sys from auth import AuthController, require, member_of, name_is import socket reload(sys)

Unable to add more than one applications together in cherryPy

∥☆過路亽.° 提交于 2019-12-08 12:04:34
问题 When I do this and try to access "/api" than cherryPy throws "TypeError: 'ApiStringGenerator' object is not callable" error ''' Created on Jan 11, 2016 @author: ankurjat ''' import cherrypy import random import string import os conf = {'/': {'tools.sessions.on': True, 'tools.staticdir.root': os.path.abspath(os.getcwd())}, '/static': {'tools.staticdir.on': True, 'tools.staticdir.dir': './resources'}, '/api': {'request.dispatch': cherrypy.dispatch.MethodDispatcher(), 'tools.sessions.on': True,

Using CherryPy as a blocking/non-threading server for easier debugging

与世无争的帅哥 提交于 2019-12-08 10:48:35
问题 Is it possible to use the CherrPy server as a blocking/non-threading server (for easier debugging?) 回答1: No. Not only does the wsgiserver start its own set of worker threads (10 by default, but even if you only specified 1 that's still 1 thread for the listening socket and 1 worker thread). Even if that were not true, if you use the rest of CherryPy (i.e. the engine), it runs that 1 listener thread in a separate thread from the main thread. 来源: https://stackoverflow.com/questions/1502431

Can't get Mako engine in CherryPy to work

荒凉一梦 提交于 2019-12-08 09:21:54
问题 I need to set up a server using CherryPy and the Mako Template Engine, though I can't get the latter to work. I started to integrate the code from >>here<< into my working CherryPy setup. Though in the end, I only see "Hello, ${username}!" as text instead of the inserted variable. Other information or examples I found via search or Google didn't solve that as well. Since the code is quite long, I use pastebin to show it. server.py app/application.py << I put another version of the index

How does CherryPy caching work?

大城市里の小女人 提交于 2019-12-08 08:54:15
问题 I recently discovered that page object attributes in CherryPy are persistent between requests (and between clients). So I'm wondering, would it make sense to store page output in such an attribute? Like this: class Page: def default(self, pagenumber): if pagenumber not in self.validpages: return 'Page number not found' try: html = self.pageoutput[pagenumber] except KeyError: html = self.formatter(self.dbcall(pagenumber)) return html default.exposed = True def formatter(self, data): html = #

Using Flask with CherryPy to serve static files

☆樱花仙子☆ 提交于 2019-12-08 02:54:06
问题 First time using a web framework, hope to get advice on the correct approach. My aim is to have a server which can return static files based on a url passed in. I use Flask as my web framework and I intent to use CherryPy as my web server. The web describes many ways of setting up Flask with CherryPy and I am not sure if I am doing it correctly. Resources I have been using: http://rhodesmill.org/brandon/2011/wsgi-under-cherrypy/ Flask, CherryPy and static content http://fgimian.github.io/blog

Psycopg / Postgres : Connections hang out randomly

不羁岁月 提交于 2019-12-08 02:41:39
问题 I'm using psycopg2 for the cherrypy app I'm currently working on and cli & phpgadmin to handle some operations manually. Here's the python code : #One connection per thread cherrypy.thread_data.pgconn = psycopg2.connect("...") ... #Later, an object is created by a thread : class dbobj(object): def __init__(self): self.connection=cherrypy.thread_data.pgconn self.curs=self.connection.cursor(cursor_factory=psycopg2.extras.DictCursor) ... #Then, try: blabla self.curs.execute(...) self.connection

How does CherryPy caching work?

白昼怎懂夜的黑 提交于 2019-12-07 15:51:32
I recently discovered that page object attributes in CherryPy are persistent between requests (and between clients). So I'm wondering, would it make sense to store page output in such an attribute? Like this: class Page: def default(self, pagenumber): if pagenumber not in self.validpages: return 'Page number not found' try: html = self.pageoutput[pagenumber] except KeyError: html = self.formatter(self.dbcall(pagenumber)) return html default.exposed = True def formatter(self, data): html = # Formatting code here return html def dbcall(self, pagenumber): data = # Database lookup code here return

Problems serving static files in CherryPy 3.1

两盒软妹~` 提交于 2019-12-07 12:21:06
问题 I'm having some trouble serving a static XML stylesheet to accompany some dynamically generated output from a CherryPy web app. Even my test case serving a static text file fails. Static file blah.txt is in the /static directory in my application root directory. In my main site file (conesearch.py contains the CherryPy ConeSearch page-handler class): import conesearch cherrypy.config.update('site.config') cherrypy.tree.mount(conesearch.ConeSearch(), "/ucac3", 'ucac3.config') ... And in site

Problems serving static files favicon.ico and robots.txt in CherryPy 3.1

牧云@^-^@ 提交于 2019-12-07 10:40:39
问题 When I try to browse to favicon.ico, for instance, I get this error: ValueError: Static tool requires an absolute filename (got 'favicon.ico') I can get to anything in my /images, /css and /js folders. Those are serving just fine. The site looks and acts great. It's just these darn two files. Here is my root.conf file. [/] tools.staticdir.on = True tools.staticdir.root = "/projects/mysite/root" tools.staticdir.dir = "" [/favicon.ico] tools.staticfile.on = True tools.staticfile.filename =