Skip to content

Use Django, Bootstrap, MySQL, Celery, Redis, Docker to build an online demo shopping site and deploy on AWS. (The website is no longer available)

Notifications You must be signed in to change notification settings

ZoeLiao/python-Django-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-Django-demo

Set up

Start an app

  • If you want to add a new app:
    • django-admin startapp <app_name>

Migrate database

  • In general cases:
    • python manage.py makemigrations
    • python manage.py migrate
  • Failed to detect changes:
    • Run the command of Management - Delete the data of specific app
    • Fake Migration:
      • Tells Django to mark the migrations as having been applied or unapplied, but without actually running the SQL to change your database schema
      • python manage.py makemigrations <app_name>
      • python manage.py migrate --fake
    • Migrate:
      • python manage.py makemigrations <app_name>
      • python manage.py migrate

Management

  • Delete the data of specific app:
    • python manage.py manual_migration <app_name>
    • e.g., python manage.py manual_migration shop

Static files

  • python manage.py collectstatic

Send emails

  • If there is not settings/local.py, create it by vim demo/settings/local.py (settings/local.py is an ignored file. (you can copy demo/settings/local_example.py and revise it.))
  • Input your email information in demo/settings/local.py:
    • EMAIL_HOST = 'smtp.gmail.com'
    • EMAIL_PORT = 587
    • EMAIL_HOST_USER = '<your_email>@gmail.com'
    • EMAIL_HOST_PASSWORD = '<your_password>'
  • Start Celery by the following command of Celery - start

Sign in with third-party accounts:

  • If there is not settings/local.py, create it by vim demo/settings/local.py (settings/local.py is an ignored file. (you can copy demo/settings/local_example.py and revise it.))
  • Input your Facebook, Instagram, GitHub key in demo/settings/local.py:
    • Facebook (If you do not have a key, please visit: facebook for developers):
      • SOCIAL_AUTH_FACEBOOK_KEY = <your Facebook key>
      • SOCIAL_AUTH_FACEBOOK_SECRET = <your Facebook secret>
    • Instagram (If you do not have a key, please visit: Instagram for developers):
      • SOCIAL_AUTH_INSTAGRAM_KEY = <your Instagram key>
      • SOCIAL_AUTH_INSTAGRAM_SECRET = <your Instagram secret>
    • GitHub (If you do not have a key, please visit: GitHub Dveloper):
      • SOCIAL_AUTH_GITHUB_KEY = <your GitHub key>
      • SOCIAL_AUTH_GITHUB_SECRET = <your GitHub secret>

Celery

Test

  • python manage.py test <app_name>.tests

i18n

  • python manage.py makemessages -l <target language>
    • e.g., python manage.py makemessages -l zh_Hant
  • vim demo/locale/<target_language>/LC_MESSAGES/django.po
    • e.g., vim demo/locale/zh_Hant/LC_MESSAGES/django.po
  • python manage.py compilemessages

Docker

  • mkdir <path>/sites-available
  • Build: docker-compose up --build
  • Run: docker-compose up
  • Remove: docker-compose down -v
  • docker system prune (-f)
  • AWS:
    • docker-compose up -d
    • sudo usermod -a -G docker $USER
    • sign out and sign in again
    • sudo service docker start
  • Container:
    • docker container ls
    • docker exec -it <Container ID> bash

Deployment

  • docker-compose up --build
  • docker exec -it <Web Container ID> bash
  • python manage.py collectstatic
  • python manage.py createsuperuser

Git

  • Git doesn't notice change in image:
    • git rm --cached path/to/image.jpg

About

Use Django, Bootstrap, MySQL, Celery, Redis, Docker to build an online demo shopping site and deploy on AWS. (The website is no longer available)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages