====== Django ======
* [[https://www.djangoproject.com/|Django Home]]
* [[https://pythonblog.co.kr/blog/1/|서버구축부터 Django Site오픈까지]]
* [[https://twowix.me/85|runserver로 실제 서버를 돌리면 안되는 이유]]
* [[python:django:graphene|Graphene-Django]]
* [[python:django:vscode|VSCode에서 Django사용]]
* [[python:django:nginx|nginx 및 uWSGI연동]]
* [[python:django:ubuntu|Ubuntu에서 wsgi와 Apache설정]]
* [[python:django:uwsgi|uWSGI]]
===== 문서 =====
Django의 LTS버전은 X.2로 배포됨.( 3.2, 4.2, 5,2 )
* [[https://www.garamx.com/django-docs-3.2-ko|Django 문서 3.2]]
* [[https://docs.djangoproject.com/ko/3.2/|Django 문서 3.2]]
* [[https://docs.djangoproject.com/ko/4.2/|Django 문서 4.2]]
* [[https://docs.djangoproject.com/ko/5.1/|Django 문서 5.1]]
===== 장고 사용 =====
* [[python:django:manage|Django Server관리]]
* [[python:django:app|Django App]]
* [[python:django:secret_key|SECRET_KEY?]]
* [[python:django:hide_key_value|Hide Key Value]]
* [[python:django:test|TestCase]]
* [[python:django:view|view만들기]]
* [[python:django:urls.py|urls.py]]
* [[python:django:settings.py|settings.py]]
* [[python:django:models|Models]]
* [[python:django:models:filter|Models.filter]]
* [[python:django:models.py|models.py]]
* [[python:django:admin|Admin 기능 사용하기]]
* [[python:django:static|정적파일관리]]
* [[python:django:request|Request & Session]]
* [[python:django:treeboard|TreeBoard]]
* [[python:django:class-based|Built-in class-based views API]]
* [[python:django:migration|DB Migration 초기화]]
* [[python:django:uwsgi|uWSGI]]
* [[python:django:nginx|Nginx와 uWSGI연동]]
* [[python:django:garam|Garam의 설정]]
* [[python:django:csrf|CSRF처리방법은?]]
* [[python:django:forms|Forms]]
* [[python:django:bcrypt|장고를 위한 암호모듈]]
===== 주요명령어 =====
* 장고 프로젝트생성
django-admin startproject "프로젝트명"
* 자주사용하는 명령어
python manage.py startapp "Application Name"
python manage.py runserver
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic
python manage.py inspectdb
===== 앱작성 =====
* 새로운 앱을 작성
$ python manage.py startapp plant
* Web Application에 등록
INSTALLED_APPS = [
'plant.apps.PlantConfig',
....
]
* 정의된 모델을 Database에서 반영
$ python manage.py makemigrations polls
* 반영된 model의 Table script보기
$ python manage.py sqlmigrate polls 0001
===== migrate =====
명령을 통해 마이그레이션을 수행하거나 데이터베이스를 건드리지 않고도 프로젝트의 문제를 확인할 수 있습니다.
$ python manage.py check
$ python manage.py makemigrations
$ python manage.py migrate
migrate 명령은 아직 적용되지 않은 마이그레이션을 모두 수집해 이를 실행하며(Django는 django_migrations 테이블을 두어 마이그레이션 적용 여부를 추적합니다) 이 과정을 통해 모델에서의 변경 사항들과 데이터베이스의 스키마의 동기화가 이루어집니다.
* (models.py 에서) 모델을 변경합니다.
* python manage.py makemigrations을 통해 이 변경사항에 대한 마이그레이션을 만드세요.
* python manage.py migrate 명령을 통해 변경사항을 데이터베이스에 적용하세요.
마이그레이션을 만드는 명령과 적용하는 명령이 분리된 것은 버전 관리 시스템에 마이그레이션을 커밋하고 앱과 함께 출시할 수 있도록 하기 위해서입니다. 이는 당신의 개발을 쉽게 해줄 뿐 아니라, 다른 개발자가 프로덕션에서 사용할 수 있게 해줍니다.
===== API가지고 놀기 =====
대화식 Python 쉘에 뛰어들어 Django API를 자유롭게 가지고 놀아봅시다. Python 쉘을 실행하려면 다음의 명령을 입력합니다.
$ python manage.py shell
>>> from polls.models import Choice, Question # Import the model classes we just wrote.
# No questions are in the system yet.
>>> Question.objects.all()
# Create a new Question.
# Support for time zones is enabled in the default settings file, so
# Django expects a datetime with tzinfo for pub_date. Use timezone.now()
# instead of datetime.datetime.now() and it will do the right thing.
>>> from django.utils import timezone
>>> q = Question(question_text="What's new?", pub_date=timezone.now())
# Save the object into the database. You have to call save() explicitly.
>>> q.save()
# Now it has an ID.
>>> q.id
1
# Access model field values via Python attributes.
>>> q.question_text
"What's new?"
>>> q.pub_date
datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=)
# Change values by changing the attributes, then calling save().
>>> q.question_text = "What's up?"
>>> q.save()
# objects.all() displays all the questions in the database.
>>> Question.objects.all()
]>
모델의 관계에 대한 더 많은 정보는 관련 객체에 접근하기를 참조하세요. API에서 이중 밑줄(__) 을 이용해서 어떻게 필드를 조회할 수 있는지는 필드 조회를 읽어보세요.데이터베이스 API에 대한 자세한 내용을 보려면, 데이터베이스 API 레퍼런스를 읽어보세요.