Question

I want to create a module containing different utility functions and classes to use across different apps. It's not going to define any models or views. What's the best way to do this?

Was it helpful?

Solution

I would delete django-specific files like models.py, forms.py, and views.py, unless you intend to use them for their standard purpose.

From there create whatever files you want to house your custom functions/classes. I usually create an app_utils.py and put everything there. You might want to split it into separate functions.

It's really up to you. Django apps are no different from any other python package. To use methods/classes in another app you'll just use

from myapp.myapp_utils import *

Another perfectly good option is just to create a Python package yourself. All that entails is creating a directory with an __init__.py file in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top