Unicode problem solved except for 1 occurrance where I must explicitly do an encode('uft-8')
I'm currently using Pylons 0.9.5 with Python 2.4 I solved the Unicode problems with Mako, so let me tell you what I did (for those that have searched countless forums as I have done). Then I'll mention what seems to be a hack that I would like to get cleared up How to get unicode working with Pylons+Mako: config/environment.py: [...snippet below...] # Add your own template options config options here, note that all config options will override # any Pylons config options tmpl_options['mako.imports'] = ['from webhelpers import auto_link as l', 'from webhelpers import simple_format as s', 'from rosetta.lib import myfilters', 'from paste.deploy import CONFIG'] # BELOW SOLVES THE UNICODE PROBLEM FOR TEMPLATES # Give support for Unicode in Mako templating system # from: http://wiki.pylonshq.com/pages/viewpage.action?pageId=5439551 tmpl_options['mako.input_encoding'] = 'utf-8' tmpl_options['mako.output_encoding'] = 'utf-8' # convert request.params to Unicode automatically # Pylons 0.9.6 does this automatically, but we are in 0.9.5 still so it must be explicit #return pylons.config.Config(tmpl_options, map, paths) # Return our loaded config object return pylons.config.Config(tmpl_options, map, paths, request_settings=dict(charset='utf-8', errors='replace')) models/__init__.py: [...snippet below...] def init_model(app_conf): Setup the model. This gets called by lib.app_globals print Initializing model. uri = app_conf['sqlalchemy.default.dburi'] # BELOW SOLVES THE UNICODE PROBLEM FOR YOUR MODEL # use: encoding='utf-8', convert_unicode=True to convert all unicode at the database level so its unicode going into python/mako engine = create_engine(uri, pool_recycle=14400, echo_pool=True, encoding='utf-8', convert_unicode=True) meta.connect(engine) meta.engine.echo = asbool(app_conf.get('sqlalchemy.default.echo', 'false')) That's it!! Ok to the ^^^QUESTION^^^... I have unicode working great, but for some reason when using the Auth plugin and the webhelpers url_for method I still need to explicitly encode the variable as utf-8. This seems a bit hacky though. Anyone else get into a similar situation and/or have a more elegant solution (or am I just doing something wrong here)? Here's a snippet of the code I'm using for that: snippet for Auth problem def signin_method(self): uname = request.params.get('username', '').strip().encode('utf-8', 'replace') - throws a UnicodeDecodeError if not first doing an encode request.environ['paste.auth_tkt.set_user'](uname) url_for problem ${ h.url_for('page', nickname=notebook.user.nickname, notebook_id=notebook.book_id, highlight = c.query.encode('utf-8', 'replace') where highlight becomes a param so the url would look something like: /users/me/1/?highlight=úñicode_phrase thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Re: Unicode problem solved except for 1 occurrance where I must explicitly do an encode('uft-8')
The question doesn't seem to call itself out, so I'll place it separately as well Ok to the ^^^QUESTION^^^... I have unicode working great, but for some reason when using the Auth plugin and the webhelpers url_for method I still need to explicitly encode the variable as utf-8. This seems a bit hacky though. Anyone else get into a similar situation and/or have a more elegant solution (or am I just doing something wrong here)? Here's a snippet of the code I'm using for that: snippet for Auth problem def signin_method(self): uname = request.params.get('username', '').strip().encode('utf-8', 'replace') - throws a UnicodeDecodeError if not first doing an encode request.environ['paste.auth_tkt.set_user'](uname) url_for problem ${ h.url_for('page', nickname=notebook.user.nickname, notebook_id=notebook.book_id, highlight = c.query.encode('utf-8', 'replace') where highlight becomes a param so the url would look something like: /users/me/1/?highlight=úñicode_phrase thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
how do i create a custom internal server error page? .htaccess?
Hi! When I turn debug to false and there is a problem with my code I am redirected to a blank page that reads internal server error. okay, that is supposed to happen... but I want my chrome around that. usually i would just define a line in my .htaccess file and point it to the page I want to display. however i don't know if htaccess is appropriate nor where to put it (I tried /public and a couple other folders and nothing seems to pick up). any ideas? thanks! john --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Re: how do i create a custom internal server error page? .htaccess?
On Feb 21, 1:40 pm, johnnyice [EMAIL PROTECTED] wrote: Hi! When I turn debug to false and there is a problem with my code I am redirected to a blank page that reads internal server error. okay, that is supposed to happen... but I want my chrome around that. usually i would just define a line in my .htaccess file and point it to the page I want to display. however i don't know if htaccess is appropriate nor where to put it (I tried /public and a couple other folders and nothing seems to pick up). It possibly depends on which level in the WSGI stack or underlying WSGI adapter for the web server you are using to host your application that generates the page. Am sure Pylons probably has an inbuilt mechanism for providing customised error pages and someone else will no doubt point you to that, but in terms of generic WSGI applications the following would apply. If somewhere down in the WSGI stack is capturing the exception and generating a complete 500 response including response content, then you would need to introduce a middleware component that detects that 500 response and changes it as it is passed up. If the exception isn't being caught and is instead propagating right back up to the WSGI server adapter and it is that which is generating the 500 response, then you would use a middleware component that catches the exception and generates a complete 500 response of its own from scratch. A more tricky situation although not likely to occur for your case, is where for some reason an error occurs within the WSGI adapter itself and it generates its own complete 500 response for that error. Because there is no user code between it and the web client, it is much harder to intercept and modify it. One possibility here though is if you are running behind mod_proxy. In that case you can intercept it in Apache by setting ProxyOverrideError to On. Doing this will result in appropriate error responses being redirected internally by Apache to the page appropriate for the ErrorDocument URL for that error status, thus allowing it to replace the error page. This is useful where you need to make error pages consistent across many applications being fronted by the one Apache. Because it is being handled in Apache though, you loose access to any context information such as stack traces which would be available to the WSGI application itself. Not even sure you get access to the original error response content as that is most likely discarded. To help answer the question you may want to be clearer about whether you are using Paste serve and/or mod_proxy. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Adding tags..
Howdy all, I've been doing python web development for a couple years now. Recently I tried Rails and found the partial or tag like functionality a very useful way to re-use display logic. I sort of built a hacky method of of tags into my pylons app. Here's how I've handled it.. 1. I create a template named foo.html in the templates directory. The template looks like this.. div${name}/div 2. I create a method in the helpers.py module that looks like this def render_foo(name): c.name = name return render(foo) 3. Now in any template I can render the tag like so ${h.render_foo(chad)} My helpers.py file is starting to get a little filled with my tags. I'd love to find a way to pull the tags out into their own directory. It would also be nice to be able to reference them in my genshi template like ${tag.render_foo} or even just ${render_foo}. What do you guys think about my tag method in general? Does anyone have any ideas on how to enable ${tag.render_foo}? Thanks, Chad --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---
Layouts in pylons
Just curious of how other pylons developers are doing site layout in their apps? Are you guys mostly using the template and includes? I'm currently using genshi and xi:include. This method works.. but it really seems like a lot of wasted code. In the past I've used several methods for site layout. Once we wrote a filter that automatically added a layout based on a url config file. We based this method off of sitemesh (http://www.opensymphony.com/sitemesh/). Rails allows you to automatically associate a layout with templates in a controller or all templates. Just curious about what other people are doing and what you think of rails/sitemesh.. Chad --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~--~~~~--~~--~--~---