우기의 알 블로그 저자 한승욱이라고 합니다.
스스로 알을 깨고 나오는 새처럼
언젠가 알을 깨고 온전한 나 자신이 되었을 때, 그때를 기다리며 제 속에서 솟아 나오는 것을 글로써 표현하고자 합니다.
'개발 기술블로그'를 위주로 저 한승욱의 다양한 관심사, 생각, 철학 등을 포스팅합니다.
> heroku login# 이후 엔터# 이후 브라우저가 열리면 로그인 후 터미널로 돌아옴
heroku 프로젝트 생성
> heroku create drf-quiz-test # 해당 이름이 Url 주소가 됨
# 오류: Name drf-quiz-test is already taken# 이름을 다르게 해서 생성> heroku create drf-quiz-test-wook
heroku 배포
> git push heroku master
migrations 파일로 migrate
> heroku run python manage.py migrate
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying auth.0012_alter_user_first_name_max_length... OK
Applying quiz.0001_initial... OK
Applying sessions.0001_initial... OK
배포하며 DB가 초기화되었기에 '관리자 계정' 새로 생성
> heroku run python manage.py createsuperuser
Running python manage.py createsuperuser on ⬢ drf-quiz-test-wook... up, run.8862 (Free)
Username (leave blank to use 'u54840'): han
Email address:
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
5. Django 배포 with Heroku
개요 - wooogy-egg.tistory.com/4
개발 환경 세팅 - wooogy-egg.tistory.com/5?category=938272
Flutter 앱 화면 및 로직 구성 - wooogy-egg.tistory.com/6
Django 백엔드 구축 - wooogy-egg.tistory.com/7
본 글을 인프런 강의를 따라서 제작해본 경험을 남기고자 작성합니다.
플러터와 장고로 1시간만에 퀴즈 앱/서버 만들기 [무작정 풀스택] - 인프런
플러터와 장고로 풀스택 퀴즈앱을 만드는 강의입니다! 배울 거리가 많은 풀스택 강의로 풀스택 개발자가 되어보세요:) 초급 모바일 앱 개발 프레임워크 및 라이브러리 서버 개발 Django Flutter 모
1) 배포를 위한 추가 패키지 설지
pip install django-cors-headers gunicorn psycopg2-binary whitenoise dj-database-url
2) requirements.txt 파일 만들기
pip freeze > requirements.txt # 패키지 의존성에 대한 텍스트 파일 만들기
3) settings.py 수정
import dj_database_url #추가 # 시크릿키 복사 후 수정 SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'rz$g17*hle_m6jq&x*1j-p&0%9^i_*p!mv7u9bv_b=_j&&cxlz') # Debug 옵션 false로 수정 DEBUG = False # MIDDLEWARE 추가 MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', # 추가 ] # DATABASE 추가 db_from_env = dj_database_url.config(conn_max_age=500) DATABASES['default'].update(db_from_env)
4) 배포를 위한 파일 만들기
# Procfile web: gunicorn myapi.wsgi
> python -V # 이거를 통해 현재 가상환경의 파이썬 버전 알아냄 Python 3.7.7 # 본인은 3.7.7 버전을 사용중 # runtime.txt python-3.7.7
# .gitignore __pycache__/ *.py[cod] .Python venv/ db.sqlite3 .DS_Store .vscode/
5) Heroku 가입 및 로그인
6) 로컬에 heroku 설치
brew install heroku/brew/heroku
7) 현재 디렉토리를 git 폴더로 만들기
> git init # 위 먼저 실행 > git add --all # 그 다음 실행 > git commit -m "Ready for deploy"
8) 깃허브 레포 생성
9) 레포 연결 및 push
> git remote add origin https://github.com/SeungWookHan/drf_quiz_test.git > git push origin master
10) heroku 설정
> heroku login # 이후 엔터 # 이후 브라우저가 열리면 로그인 후 터미널로 돌아옴
> heroku create drf-quiz-test # 해당 이름이 Url 주소가 됨 # 오류: Name drf-quiz-test is already taken # 이름을 다르게 해서 생성 > heroku create drf-quiz-test-wook
> git push heroku master
> heroku run python manage.py migrate Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying auth.0012_alter_user_first_name_max_length... OK Applying quiz.0001_initial... OK Applying sessions.0001_initial... OK
> heroku run python manage.py createsuperuser Running python manage.py createsuperuser on ⬢ drf-quiz-test-wook... up, run.8862 (Free) Username (leave blank to use 'u54840'): han Email address: Password: Password (again): This password is too short. It must contain at least 8 characters. This password is too common. Bypass password validation and create user anyway? [y/N]: y Superuser created successfully.
> heroku open
11) 작성한 api가 잘 노출되는 확인함
'기술개발 > Django' 카테고리의 다른 글