trendrr / whirlwind

Framework built on top of todays fastest tech (tornado, mako templates, mongo db)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Middleware

goojo opened this issue · comments

How would I create a custom middleware for my project, I tried adding a directory at:

/application/middleware

and then adding:

"application.middleware.mymiddle" to the config but don't seem to be able to get it to load - does the middleware need to exist in the dist-packages path, along with the others?

thanks
john

Hi John,

As long as you have the middleware class setup correctly it's just a matter of declaring the middleware in your config file. See https://github.com/trendrr/whirlwind/blob/master/whirlwind/conf/app_template/config/settings.py#L58

Sounds like you already have but if you need a reference, you can take a look at: https://github.com/trendrr/whirlwind/tree/master/whirlwind/middleware/flash

best,
-M

Thanks - I got it working I had:

application.middleware.redis.middleware.SessionMiddleware
and needed only:
middleware.redis.middleware.SessionMiddleware

I'm doing a project with Whirlwind where mongo isn't needed - so removing its dependencies. I also spotted that the session middleware pulls the user from mongo every request which seems a little DB heavy - couldn't the user just be stored in the session - this makes even more sense when using redis for session store.