I am new to django and have been working on a project where i need to send regular mails to my clients from different modules in my django project.
I wanted to know if there is any provision in django using which i can create a reusable component which can be used globally in my project.
The purpose is to create a mail sending function using a third party api and to call it from anywhere in my application just by passing the required parameters.
Assuming that you have a single django app in your project, you could define all your reusable methods inside a
methods.py
file in your app folder and then import it to use the functions.If you have multiple apps, Then define create this
methods.py
in one of your app. Now lets say your project name iscoolprojectname
and the name of app which hasmethods.py
isappwithmethodsscript
, then you can usefrom coolprojectname.appwithmethodsscript import methods
Reference