a repository to have a ready-to-deploy django project. follow these steps to prepare the project and :
before doing all the previous steps we need to mount the project in the development machine, then create the new repo where the project will be launched.
-
clone the cliche_django project from github changing the name of the folder that will contain the project
git clone https://github.com/leoBitto/cliche_django.git <name of the new project>
-
create a new empty repo in github that will contain the entire project
-
change the remote version of the repo we just created in the the dev machine ( the cloned cliche ) to the repo we created on github
git remote set-url <URL of the new repo on github>
-
finally mount the project: clone all the apps you need inside the project (the src directory) as submodules
git submodule add <URL to submodule>
-
the setting file must be updated with all the django apps we intend to use and added the new set of urls the application use in the urls.py file. In settings.py:
- update the INSTALLED_APPS list with the apps we use
- update the ALLOWED_HOSTS to include the ip address of the server and the domain name
In urls.py:
- include the app urls inside the file
- enter server
- update the server
-
apt update
#update repo -
apt upgrade
#upgrade repo a reboot may be necessary -
apt install virtualenv python3-venv python3-dev libpq-dev postgresql postgresql-contrib nginx curl
# install all the packages
-
- create user
adduser <choose a user name>
#create the userusermod -aG sudo <the user name chosen>
#modify the provileges of the usersu <the user name chosen>
# switch to the user
- change the directory to the home of the new user
- clone from git
git clone <url to repo> <name of the directory you want to put the cloned repo>
- cd inside the new folder
- create virtualenv called env_dj
virtualenv env_dj
'myproject' is the name of the DB 'myprojectuser' is the name of the user that has been created
sudo -u postgres psql
CREATE DATABASE myproject;
CREATE USER myprojectuser WITH PASSWORD 'password';
# password must be between quotesALTER ROLE myprojectuser SET client_encoding TO 'utf8';
ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myprojectuser SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
\q
# close the prompt
- DATABASE_NAME=myproject
- DATABASE_USER=myprojectuser
- DATABASE_PASS='password' # password must be between quotes
- SECRET_KEY=also create a new secret key
- DEBUG=FALSE
the django project is inside the /src folder, in here reside all the code necessary to make the django project work. inside the folder /base there are the basic setting and the .env file. inside the /src folder, along with the /base folder there will be all the django app
from the main folder
-
activate environment
source env_dj/bin/activate
-
install resources in pip from requirements
pip install -r requirements.txt
-
change directory to the /src directory
cd /src
-
manage.py
python manage.py makemigrations
# create migrationspython manage.py migrate
# effectively migratepython manage.py createsuperuser
# create the superuserpython manage.py collectstatic
# gather everythin inside a static folder
-
exit environment
deactivate
Also we need to update the allowed hosts to include the ip address of the server and the domain name.
now you can call the script inside the script folder
sudo ./set_pro_server.sh
NB you may need to call the scripts inside the apps to make everything work