$ pip install virtualenv
(I always like to called the virtual environment as venv)
$ virtualenv venv
$ cd venv
$ scripts\activate
$ source bin\activate
$ cd ..
$ cd src
$ pip install -r requirements-dev.txt
$ pip install -r requirements-prod.txt
Then I create the django project.
$ django-admin startproject project_name
But anyone who use this boilerplate will already create a project called mysite which is inside the src folder
A management custom command added to rename project name and all the related places where changes must be done to run the project.
$ python manage.py rename project_name
so current folder structure would be like this...
django-project-boilerplate(project folder)
--.git
--src(root folder)
----core
----mysite
----manage.py
----(...)
--venv
--README.md
--LICENSE
For security purpose this boilerplate uses python-decouple to secure all sensitive variables like SECRECT_KEY, Production level database username, password etc to a secure file called .env
For local development you can rename the .env.example file to .env to run the project on local computer.
There are two instruction file(project folder) on how to deploy django projects on heroku and digital ocean (I am continuously updating these to file) and more like AWS and others will be added in the future.
The boilerplate can be improved so please let me know how to improve...
In the src folder there are three apps already created by default
- core
- pages
- accounts
Django suggest if any custom command has to create for a project it should be on the core > management > command folder. Like I created the rename command
I created the pages app to handle the main pages like index(home), about, contact etc for now. Also I created the placeholder pages in the template folder of the pages folder.
I created the accounts app to handle the pages like login, register, dashboard etc for now. Also I created the placeholder pages in the templates folder of the accounts folder.
src > mysite > settings There are three file
- base.py
- developement.py
- production.py
base.py file has contain things that both needed for both development and production settings.
Development settings included Django debug tools and which is helpful for debugging a Django project.
Production settings I configured Database to use PostgreSQL so to secure the database sensitive information like DB_NAME, DB_USER, DB_PASSWORD etc I use the python-decouple module.
By default python-decouple check for .env file for sensitive information of the project.
This .env file should not be push on the public repository. You can create variable on the hosting site so just created their will auto fetch value by python-decouple module.
Checkout the .env.example file to create a .env file
Note .env.example file contain the Django project SECRET_KEY and it's just a 50 character long random number so you change it when you use this boilerplate.
If anyone want to change the project to use the production settings just change one place only.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings.development') to os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings.production')