turbogears2

how to check if request is ajax in turbogears

江枫思渺然 提交于 2020-01-03 05:32:07
问题 How do I go about checking if a request is an ajax request in a controller method in Turbogears? Further, is it possible to return a 'partial' much like in rails or symfony if the request is an ajax request. I know about the json decorator but I need a way to return a partial of a mako template (because I need to format the data and don't want to to do it all in Javascript). For example if I want to return the formatted list for page two of a list of news stories, I do not want to return the

How to initialize global variables in TurboGears 2 with values from a table

流过昼夜 提交于 2019-12-24 21:07:24
问题 I need a global variable that I can call from the templates. I edited app_globals.py in lib directory to declare PATH_TO_IMAGES like this class Globals(object): """Container for objects available throughout the life of the application. One instance of Globals is created during application initialization and is available during requests via the 'app_globals' variable. """ PATH_TO_IMAGES = "" def __init__(self): """Do nothing, by default.""" pass Now I can call from any template the image path

TurboGears 2 quickstart shows error immediately

末鹿安然 提交于 2019-12-23 12:44:20
问题 I am new to TurboGears and have just installed TG2 development in a virtual environment. I'm following along in the quickstart guide, and have successfully built a helloworld via paster quickstart I started the server and navigated a web-browser to localhost:8080 Wouldn't you know it, I immediately get an error, and not the welcome message the documentation suggests I should be seeing. The error reads: AttributeError: 'AcceptLanguage' object has no attribute 'best_matches' Here's the trace:

How to extend the Turbogears 2.1 login functionality

空扰寡人 提交于 2019-12-12 12:15:25
问题 I'm using Turbogears 2.1 and repoze.who/what and am having trouble figuring out how to extend the basic authentication functionality. I am essentially attempting to require users to activate their account via an emailed link before they can login. If they try to login without activating their account, I want to display an appropriate error message. The default Turbogears functionality simply displays one message for all errors. I created my own authentication plugin which works fine. It won't

Simple ascii url encoding with python

萝らか妹 提交于 2019-12-04 02:15:57
问题 look at that: import urllib print urllib.urlencode(dict(bla='Ã')) the output is bla=%C3%BC what I want is simple, I want the output in ascii instead of utf-8, so I need the output: bla=%C3 if I try: urllib.urlencode(dict(bla='Ã'.decode('iso-8859-1'))) doesn't work (all my python files are utf-8 encoded): 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) In production, the input comes unicoded. 回答1: Have a look at unicode transliteration in python: from unidecode