Code Monkey home page Code Monkey logo

tornroutes's Introduction

tornroutes

Provides a route decorator for the Tornado framework.

Installation

This package is available via pip with pip install tornroutes for the stable version.

You can also install the latest source (also usually very stable) by the following:

pip install -e git+git://github.com/nod/tornroutes.git#egg=tornroutes

Testing

Pretty well tested. You can run them with nosetests if you have nose installed.

The following run in the base directory of the repo will run the tests:

virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
nosetests

Usage

The best source of information is the comments in tornroutes/init.py.

simple example

import tornado.web
from tornroutes import route

@route('/blah')
class SomeHandler(tornado.web.RequestHandler):
    pass

t = tornado.web.Application(route.get_routes(), {'some app': 'settings'}

generic_route example

Example carried over from above, if you have a template at generic.html and you want it to get rendered at a certain uri, do the following:

generic_route('/generic/?', 'generic.html')

authed_generic_route example

Often, tornado projects end up defining something like BaseHandler that extends tornado.web.RequestHandler and defines methods necessary for authentication.

This handler might look like:

class BaseHandler(RequestHandler):
    def get_current_user(self):
        """ do stuff here to authenticate the user """
        return None # NONE SHALL PASS

Which allows us to provide authenticated generic routes:

from tornroutes import authed_generic_route

authed_generic_route('/locked', 'some_locked_template.html', BaseHandler)

Now, you'll have a uri of /locked being answered with a render of some_locked_template.html if the user is authenticated, otherwise, they get redirected to the value set at settings.login_url.

tornroutes's People

Contributors

nod avatar symbiont-andrew-leinung avatar

Watchers

Andrew-liu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.