Code Monkey home page Code Monkey logo

python-django-demo's Introduction

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

python-django-demo's People

Contributors

zoeliao avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.