Skip to content
This repository was archived by the owner on Oct 2, 2021. It is now read-only.
This repository was archived by the owner on Oct 2, 2021. It is now read-only.

Django SECRET_KEY 분리 #10

@hatchling13

Description

@hatchling13

개요

manage.py startproject를 통해 새로운 Django 프로젝트를 생성하면, 생성된 프로젝트의 설정을 관리하는 settings.py 파일에 SECRET_KEY 값을 무작위로 생성한다. SECRET_KEY 값은 외부에 공개되면 안되지만, 현재 저장소에 해당 값이 노출되어있는 상태이다. 현재로써는 실제로 돌고 있는 프로젝트가 아니기 때문에 괜찮지만, 서비스를 개시하기 위해서는 해당 값을 따로 보관해야 한다. 다음의 2가지 방법을 생각할 수 있다:

1. 환경변수

import os
SECRET_KEY = os.environ['SECRET_KEY']

2. 별도 파일 저장

with open('/etc/secret_key.txt') as f:
    SECRET_KEY = f.read().strip()

현재 프로젝트는 docker 이미지가 되어 배포될 예정이라는 것도 참고해야 한다.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions