Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    Flask-Genshi 0.5.1

    Download button

    No screenshots available
    Downloads: 284  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    Excellent (5.0/5)
    2 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Dag Odenhall | More programs
    BSD License / FREE
    November 28th, 2010, 06:56 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Flask-Genshi description

    An extension to Flask for easy Genshi templating

    Flask-Genshi is a Flask extension that allows you to easily use Genshi for templating. It knows how to render a template based on the file extension and can create Response objects with mimetype set accordingly.

    Installation

    Just grab it from PyPI with easy_install or pip, for example:

    easy_install Flask-Genshi

    If you’re starting a new project you don’t need to explicitly install Flask as Flask-Genshi depends on it already.

    How to Use

    You need to construct a Genshi with your Flask instance.

    from flaskext.genshi import Genshi

    app = Flask(__name__)
    genshi = Genshi(app)


    The best way to render templates is to use render_response(). This ensures that the proper mimetype is sent if you render XHTML, XML or text, and sets the right doctype for you.

    Use it like so:

    from flaskext.genshi import render_response

    @app.route('/')
    def index():
     title = 'Genshi + Flask, a match made in heaven!'
     return render_response('index.html', dict(title=title))


    Using Methods

    Methods control things such as the doctype and how end tags are rendered, and with render_response() also the mimetype. Unless overridden the method used is decided by the template’s filename extension.

    By default HTML renders as strict HTML 4.01. This is how you change it to HTML5:

    genshi.extensions['html'] = 'html5'

    I recommend against this but of course you can also change it to XHTML:

    genshi.extensions['html'] = 'xhtml'

    You can also override the default with a parameter to the templating functions:

    render_response('video.html', method='html5')

    The extensions html, xml, txt, js and css are recognized, but you can add any extension and method you like. Note that txt, js and css templates are rendered with genshi.template.NewTextTemplate which is not XML-based. Rendering javascript with templates gives you tools like flask.url_for() and rendering CSS with templates gives you dynamic stylesheets with things like variables.

    API Reference

    class flaskext.genshi.Genshi(app)

     extensions
     What method is used for an extension.

     methods
     Render methods.

     template_loader
     A genshi.template.TemplateLoader that loads templates from the same place as Flask.

    flaskext.genshi.select_method(template, method=None)
     Selects a method from Genshi.methods based on the file extension of template and Genshi.extensions, or based on method.

    flaskext.genshi.generate_template(template, context=None, method=None)
     Creates a Genshi template stream that you can run filters and transformations on.

    flaskext.genshi.render_template(template, context=None, method=None)
     Renders a template to a string.

    flaskext.genshi.render_response(template, context=None, method=None)
     Renders a template and wraps it in a response_class with mimetype set according to the rendering method.


    Product's homepage

    Requirements:

    · Python
    · Flask

      


    TAGS:

    Genshi templating | Flask extension | Flask | Genshi | templating

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM