Where to include libraries I write in a django app
43 views
Skip to first unread message
Scott McKissock
unread,
Mar 11, 2023, 7:04:10 PM3/11/23
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Django/Python noob question. What is the convention for including utility packages/modules within a django app?
I have a bit of code that will only be used in a single django app, and I'd like to write tests for it and use it within the app. Should I just put it in a directory/package in the root of the app?
bck...@gmail.com
unread,
Mar 13, 2023, 2:23:19 PM3/13/23
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hi Scott,
Yes, generally single-app relevant utility code should be included as additional modules within that app. Some examples:
my_app
├── __init__.py
├── apps.py
├── models.py
├── urls.py
├── utils.py # include utility code as another module
└── views.py
my_app
├── __init__.py
├── apps.py
├── models.py
├── urls.py
├── utils # break out more complicated utility code into a package
│ ├── __init__.py
│ ├── utility1.py
│ └── utility2.py
└── views.py
If the utility grows and becomes useful across a range of apps and deployments you might then consider breaking it out into its own python package that could be installable independently of the original Django app.
Brian
Scott McKissock
unread,
Mar 14, 2023, 9:32:22 AM3/14/23
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message