-
Notifications
You must be signed in to change notification settings - Fork 1
02 Django Project Initial Setups
2005869 edited this page Apr 29, 2022
·
1 revision
-
Clone github repository, create the following directories to organize the project:
- django_project - For Django project folder.
- devops - For docker deployment.
- ...
-
Create Virtual Environment
python3 -m venv venv
-
Activate Virtual Environment:
source venv/bin/activate
-
Install Django Library:
pip install django django-allauth gunicorn mysqlclient django-environ
pip freeze > requirements.txt
-
Create Django Base Project: Name = config
django-admin startproject config .
-
Edit ./config/Settings.py
LANGUAGE_CODE = 'pt-BR'
TIME_ZONE = 'America/Sao_Paulo'
import os
- Add on TEMPLATES =
'DIRS': [os.path.join(BASE_DIR, 'templates')],
- Create directory:
./templates
ALLOWED_HOSTS = ['*']
CSRF_TRUSTED_ORIGINS = ['https://bee.espertamente.com.br','http://bee.espertamente.com.br','http://localhost','http://127.0.0.1','http://localhost:8080','http://127.0.0.1:8080']
-
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'templates/static'),) STATIC_ROOT = os.path.join('static')
- During development we will use SQLite3 and after finish it, we will migrate it to MySQL.
python3 manage.py makemigrations
python3 manage.py migrate
- Run the following command (do not forget to remain inside the venv)
python3 manage.py createsuperuser
- Run the following command (do not forget to remain inside the venv)
python3 manage.py runserver
- Run the following command (do not forget to remain inside the venv)
- Before, for Ubuntu, You may need to install the Python 3 and MySQL development headers and libraries like so:
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
pip install mysqlclient
-
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'django_project', 'USER': 'django_project', 'PASSWORD': 'PASSWORD', 'HOST': '127.0.0.1', 'PORT': '3306', } }
- Before, for Ubuntu, You may need to install the Python 3 and MySQL development headers and libraries like so: