23👍
Create a folder, say utils, and make it a module by creating __init__.py
inside it.
Now create any script under this folder. Let’s say you have a file called utils.py that contains some of your python code and you want to import it.
Wherever you want to import then import your python script like
from utils.utils import YourClassOrFunction
1👍
You can have additional files that have generic code in their own files and just import them when you need them for your views, or whatever. If they are only going to be used in one app, then just put them in that apps folder. If they are more generic then you can put them in a file or folder that isn’t part of any particular app.
Django does some magic with files and folders it expects to exist, but you can put other files wherever you want it works like any other Python project.
- Django.db.utils.ProgrammingError: cannot cast type uuid to integer
- Configuring root logger in python
- Getting "OSError: dlopen() failed to load a library: cairo / cairo-2" on Windows
- Django models and Python properties
- Adding link to django admin page
0👍
Adding project path should be done at your manage.py
, but if you wanted to do something before your request reached views.py
you can use middlewares
. https://docs.djangoproject.com/en/1.8/topics/http/middleware/
- How to add custom error codes to Django Rest Framework
- What are some alternative for ModelChoiceField for large number of choices?
- My Django installs in virtual env are missing admin templates folder
- Place to set SQLite PRAGMA option in Django project
- Implementing HATEOAS in Django REST framework