Skip to content

02 Django Project Initial Setups

2005869 edited this page Apr 29, 2022 · 1 revision

01 - Django Project Start-up

  1. Clone github repository, create the following directories to organize the project:

    1. django_project - For Django project folder.
    2. devops - For docker deployment.
    3. ...
  2. Create Virtual Environment

    1. python3 -m venv venv
  3. Activate Virtual Environment:

    1. source venv/bin/activate
  4. Install Django Library:

    1. pip install django django-allauth gunicorn mysqlclient django-environ
    2. pip freeze > requirements.txt
  5. Create Django Base Project: Name = config

    1. django-admin startproject config .
  6. Edit ./config/Settings.py

    1. LANGUAGE_CODE = 'pt-BR'
    2. TIME_ZONE = 'America/Sao_Paulo'
    3. import os
    4. Add on TEMPLATES = 'DIRS': [os.path.join(BASE_DIR, 'templates')],
    5. Create directory: ./templates
    6. ALLOWED_HOSTS = ['*']
    7. 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']
    8. STATICFILES_DIRS = (os.path.join(BASE_DIR, 'templates/static'),)
      STATIC_ROOT = os.path.join('static')
      

03 - Create DB

  1. During development we will use SQLite3 and after finish it, we will migrate it to MySQL.
    1. python3 manage.py makemigrations
    2. python3 manage.py migrate

04 - Crate SuperUser

  1. Run the following command (do not forget to remain inside the venv)
    1. python3 manage.py createsuperuser

05 - Run Development Server

  1. Run the following command (do not forget to remain inside the venv)
    1. python3 manage.py runserver

05 - Setup MySQL

  1. Run the following command (do not forget to remain inside the venv)
    1. 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
    2. pip install mysqlclient
    3. DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.mysql',
              'NAME': 'django_project',
              'USER': 'django_project',
              'PASSWORD': 'PASSWORD',
              'HOST': '127.0.0.1',
              'PORT': '3306',
          }
      }