Django: Where to put helper functions?


I have a couple of functions that i wrote that I need to use in my django app. Where would I put the file with them and how would i make them callable whithin my views?

12/16/2009 4:44:50 AM

Accepted Answer

I usually put such app specific helper function in file and use someting like this

from myapp.utils import my_cool_func

def view_coolness(request):
    data = my_cool_func(request)
    return render_to_response("xxx.html")

but it depends what you helper does, may be they modify request , the could be part of middleware, so you need to tell what exactly those helper functions do

2/1/2014 6:41:08 PM

create a reusable app that include your generic functions so you can share between projects.

use for example a git repo to store this app and manage deployments and evolution (submodule)

use a public git repo so you can share with the community :)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow