Django: Where to put helper functions?

I have several functions that I wrote that I need to use django in my application. Where would I put the file with them and how would I make them callable in my views?

+42
python django
Dec 16 '09 at 4:44
source share
4 answers

I usually add such a special helper function for the application to the utils.py file and use the following role

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 on what your assistant does, maybe he modifies the request, maybe part of the middleware, so you need to say what exactly these auxiliary functions do

+45
Dec 16 '09 at 4:50
source share

If they are associated with a specific application, I usually just put them in the appropriate application folder and name the file "functions.py".

If they are not application specific, you can simply create a folder with the functions of the “function” and place them there.

+7
Dec 16 '09 at 4:50
source share

Create a reusable application that includes your common features so you can share between projects.

use, for example, the git repository to save this application and manage deployment and evolution (a submodule)

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

+6
Dec 16 '09 at 11:28
source share

I am using the new python service.py file in the application folder. The file contains mainly helper requests for a specific application. I also used to create a folder inside a Django application that contains global helper functions and constants.

+1
Nov 07
source share



All Articles