Skip to content

Latest commit

 

History

History
99 lines (74 loc) · 1.62 KB

File metadata and controls

99 lines (74 loc) · 1.62 KB

Django basic enviroment configuration

settings.py

time & language

Item Value Remarks
LANGUAGE LANGUAGE_CODE = 'zh-Hans' -
TIME_ZONE TIME_ZONE = 'Asia/Shanghai' -
USE_TZ USE_TZ = False 不使用时区

Database

Sqlite

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

Mysql

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'name',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '3306',
        'OPTIONS': {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},
        'AUTOCOMMIT': True
    }
}

参考链接

  1. Django documents
  2. Django database
  3. Time zones

Djangorestframework

installization

(env)# pip install djangorestframework

configuration in settings.py

INSTALLED_APPS = [
    'rest_framework'
]

configuration in urls.py

Deploy

requirement.txt

pip freeze > requirements.txt

docker-compose

Dockerfile

FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /www
WORKDIR /www
COPY . /www/
RUN pip install -r requirements.txt

docker-compose.yml

version: '3'

services:
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/www
    ports:
      - "80:8000"