Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIgor Yamshchykov
24,397 PointsDjango complex business logic folder structure
Hello, I have Django and in particular django view I'm implementing custom business logic for email sending on POST request, my code became quite complex and it there are few places I could separate into different functions so currently it looks something like this in myapp/views.py
class SendMessege(generics.CreateAPIView):
'''
Sends email message API
'''
def post(self, request):
# Lots of code here
My question is - where should I put those helper functions, I know that in javascript for instance I'd create some kind of lib folder and putted my helper functions there, is there a common practice to handle this cases in Django ? Thank you.
Igor Yamshchykov
24,397 PointsThey are mostly implementing custom business logic of my application, it's not general stuff like access or mutators Probably complex custom logic that can be separated in different classes or a package. Kenneth Love could you please give a hint on this one ?
1 Answer
Kenneth Love
Treehouse Guest TeacherIt's not uncommon to have a utils.py
that holds onto...well, utility functions. If it's stuff that can be heavily abstracted, you might consider making a whole new package for it. That package can, of course, just live somewhere near the app you're working on, it doesn't have to actually be an installable package.
I'd start by making a mail.py
and putting all of that logic into there, as abstract as possible, as functions and/or classes. Then see what I'm left with.
Igor Yamshchykov
24,397 PointsThank you !
Gerald Wells
12,763 PointsGerald Wells
12,763 Pointsjust trying to get a better understanding: