장고)일단 배포 때리고 프로젝트 시작하기!

2024. 10. 2. 10:57카테고리 없음

보통은, 프로젝트 완성 후에 배포를 하지만! 나는 배포를 하고 프로젝트 디벨롭을 하려고 한다 
이유는?
- 배포할 때 시간 단축을 위해서이다. 프로젝트가 무거워질수록 배포할 때 까다로워지고, 오류도 계속 발생하는데 (버전 차이 등)
- 배포를 처음에 때려버리고 프로젝트 디벨롭을 같이 하면서 배포한 곳에 계속 올리면 효율적일 거 같아서이다!

 

 

 

자 그럼 뭘 해야할까 ? 

가벼운 순서는 이렇게 될 거 같다.

 

- 깃허브 파기

- 가벼운 프로젝트 생성

- 깃에 올리기

- EC2 인스턴스 생성

- 인스턴스 접속 후 깃클론~

- NginX, gunicorn 등 깔기

- 끝?!(아마도...

 

오케 그럼 바로 ㄱㄱ 

 

- 깃허브 파기

이름은 아무거나 하시고,,,, public으로 설정 후 만들어주십셔

 

 

아시는 분들은 아시겠지만 ? 저 노란색 박스 터미널에 붙여넣으시면 깃연결은 끝난답니다 ..? 

 

 

어쨌든, 이렇게 띄워놓고 대충 폴더 하나 만들어서 깃 먼저 연결 해주자구요 ~ 

ㄹㅇ 폴더만 하나 만들었습니다?

 

 

아까 그거 복사 해서 ? 복붙하고 엔터 치시면?

 

예 뭐... 잘 된 거 같습니다! 

리드미도 잘 생겼고 ! 어쨌든 다음단계로 넘어가봅시당

 

- 가벼운 프로젝트 생성

머릿속에 떠오르는 순서?(체크리스트)는 다음과 같음

- 가상환경을 만든다

command + shift + p -> 가상환경 만들기

- 장고를 깐다

pip install django

- 프로젝트를 만든다

django-admin startproject 프로젝트이름

- 앱을 깐다-> 등록도!

python manage.py startapp 앱이름 (manage.py가 있는 곳에서 해야함)

- urls.py 작성

#urls.py
path('post/', include("post.urls")),
#post/urls.py

from django.urls import path
from . import views

app_name = 'post'

urlpatterns = [
    path("index/", views.post, name="post"),
]

 

- views.py 작성

#post/views.py

from django.shortcuts import render

def post(request):
    return render(request, "post/index.html")

 

- 템플릿폴더 & index.html 을 만든다

작성한 index.html 정말 아무것도 안 건드림,,, h1 태그만 씀!

 

- runserver해서 잘 작동하는지 본다

server 실행 후 들어옴!
post/index Page로 들어왔고 h1태그로 작성한게 잘 보임!

 

오케이 ~ 이제 가벼운 프로젝트는 완성 됐고 깃에 올리기 전에 config 와 ignore 설정 해주자!

- config.py

config.py 만들고 그 안에 secret_key를 넣어줘야한다. (왜? 이건 깃에 올라가면 안 되니까~)

시크릿키는 settings.py 에 가면 있다

#config.py
DJANGO_SECRET_KEY = '시크릿키를 넣어주세요'

settings.py 에 있는 secret key 옮겨다가 붙여놓고

 

 

#settings.py

from . import config

SECRET_KEY = config.DJANGO_SECRET_KEY

secret key 가 있던 자리는 config 경로를 알려준다

 

다 설정이 끝났으면 ? runserver해서 잘 작동하는지 확인 해주고 (난 잘 됐음)

이 상태로 올리면 안됩니당 ignore 파일도 만들어줍시다 위치는? 최상단 디렉토리! 

내가 쓴 .gitignore가 보고 싶다면 ? ⬇️⬇️⬇️⬇️⬇️

더보기
 

 

### Custom ###
config.py

 

### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media

 

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/

 

### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class

 

# C extensions
*.so

 

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

 

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

 

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

 

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

 

# Translations
*.mo

 

# Django stuff:

 

# Flask stuff:
instance/
.webassets-cache

 

# Scrapy stuff:
.scrapy

 

# Sphinx documentation
docs/_build/

 

# PyBuilder
.pybuilder/
target/

 

# Jupyter Notebook
.ipynb_checkpoints

 

# IPython
profile_default/
ipython_config.py

 

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

 

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

 

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#poetry.lock

 

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
.pdm.toml

 

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

 

# Celery stuff
celerybeat-schedule
celerybeat.pid

 

# SageMath parsed files
*.sage.py

 

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

 

# Spyder project settings
.spyderproject
.spyproject

 

# Rope project settings
.ropeproject

 

# mkdocs documentation
/site

 

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

 

# Pyre type checker
.pyre/

 

# pytype static type analyzer
.pytype/

 

# Cython debug symbols
cython_debug/

 

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

 

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

 

# Icon must end with two \r
Icon



# Thumbnails
._*

 

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

 

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

 

### macOS Patch ###
# iCloud generated files
*.icloud

 

### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider

 

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

 

# AWS User-specific
.idea/**/aws.xml

 

# Generated files
.idea/**/contentModel.xml

 

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

 

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

 

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

 

# CMake
cmake-build-*/

 

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

 

# File-based project format
*.iws

 

# IntelliJ
out/

 

# mpeltonen/sbt-idea plugin
.idea_modules/

 

# JIRA plugin
atlassian-ide-plugin.xml

 

# Cursive Clojure plugin
.idea/replstate.xml

 

# SonarLint plugin
.idea/sonarlint/

 

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

 

# Editor-based Rest Client
.idea/httpRequests

 

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

 

### PyCharm Patch ###

 

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

 

# Sonarlint plugin
.idea/**/sonarlint/

 

# SonarQube Plugin
.idea/**/sonarIssues.xml

 

# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

 

# Cache file creation bug
.idea/$CACHE_FILE$

 

# CodeStream plugin
.idea/codestream.xml

 

# Azure Toolkit for IntelliJ plugin
.idea/**/azureSettings.xml

 

### Python ###
# Byte-compiled / optimized / DLL files

 

# C extensions

 

# Distribution / packaging

 

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.

 

# Installer logs

 

# Unit test / coverage reports

 

# Translations

 

# Django stuff:

 

# Flask stuff:

 

# Scrapy stuff:

 

# Sphinx documentation

 

# PyBuilder

 

# Jupyter Notebook

 

# IPython

 

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

 

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.

 

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.

 

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.

 

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm

 

# Celery stuff

 

# SageMath parsed files

 

# Environments

 

# Spyder project settings

 

# Rope project settings

 

# mkdocs documentation

 

# mypy

 

# Pyre type checker

 

# pytype static type analyzer

 

# Cython debug symbols

 

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.

 

### Python Patch ###
poetry.toml

 

# ruff
.ruff_cache/

 

# LSP config files
pyrightconfig.json

 

### venv ###
# Virtualenv
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json

 

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

 

# Local History for Visual Studio Code
.history/

 

# Built Visual Studio Code Extensions
*.vsix

 

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

 

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

 

# Dump file
*.stackdump

 

# Folder config file
[Dd]esktop.ini

 

# Recycle Bin used on file shares
$RECYCLE.BIN/

 

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

 

# Windows shortcuts
*.lnk

 



오 config 와 venv 등 눈이 꺼진 걸 보니 잘 설정이 된 거 같습니다! 

혹시 몰라? runserver 도 한 번 더 해봤는데 잘 작동도 하네용 

이제 깃에 올립시다~ 

 

올리기 전에 ? requirements.txt 만들어야함 ... (하 난 까먹어서 다시 돌아왔다 흑)

pip freeze > requirements.txt

 

 

- git에 올리기

#터미널에서

git add .
git commit -m"새로운 프로젝트 생성"
git push origin main

 

확인해보면 잘 올라가있는 걸 볼 수 있다 !

 

 

이쯤에서 다시 보는 체크리스트!

 

- 깃허브 파기

- 가벼운 프로젝트 생성

- 깃에 올리기

- EC2 인스턴스 생성

- 인스턴스 접속 후 깃클론~

- NginX, gunicorn 등 깔기

- 끝?!(아마도...

 

와 - 이제 절반 했다 - (긍정적)

글이 너무 길어지는 거 같아서 한 번 끊고 가겠습니다 !