파이썬 장고
DB CAFE
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
1 장고[편집]
1.1 모듈 구성도[편집]
1.2 프레임워크 구조[편집]
1.2.1 장고 파일 구조[편집]
├── db.sqlite3
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── app
├── __init__.py
├── admin.py
├── apps.py
├── migrations
│ └── __init__.py
├── models.py
├── tests.py
└── views.py
</souce>
== 가상화 ==
source myvenv/bin/activate
== 프로젝트시작==
django-admin startproject myprj .
== 디렉토리구조 ==
=== manage.py ===
* 사이트 관리
* 서버시작
* python manage.py runserver
* python manage.py runserver 0.0.0.0:8000
=== settings.py ===
* 웹사이트설정
* TIME_ZONE
* = 'Asia/Seoul'
* STATIC_URL
* = '/static/'
* 정적파일위치
* CSS
* STATIC_ROOT
* = os.path.join(BASE_DIR,'static')
* ALLOWED_HOSTS
* = ''
* 로컬호스트
* [::1]
* 127.0.0.1
* 배포시
* ALLOWED_HOSTS
* = ['127.0.0.1','.xxx.com']
* MESSAGE_STORAGE
* 크롬북 사용자 일때
* = 'django.contrib.messages.storage.session.SessionStorage'
* DATABASES
* = {
'default' : {
'ENGINE': 'django.db.backends.sqlite3','NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
* DB설정
* python manage.py migrate
* DB생성 명령
* INSTALLED_APPS
* = [
......
,blog',
]
* urls.py
* wsgi.py
* __init__.py
=== 어플리케이션생성 ===
<source lang=python>
python manage.py startapp blog
</python>
<source lang=python>
* blog
* migrations
* __init__.py
* __init__.py
* admin.py
* models.py
* 데이터모델생성
* 전체소스...
* > from django.db import models
* > from django.utils import timezone
* >
* >
* > class Post(models.Model):
* > author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
* > title = models.CharField(max_length=200)
* > text = models.TextField()
* > created_date = models.DateTimeField(
* > default=timezone.now)
* > published_date = models.DateTimeField(
* > blank=True, null=True)
* >
* > def publish(self):
* > self.published_date = timezone.now()
* > self.save()
* >
* > def __str__(self):
* > return self.title
* from django.db import models
* from django.utils import timezone
* class Post(models.Model):
* author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
* 저자 컬럼
* title = models.CharField(max_length=200)
* 타이틀 컬럼
* text = models.TextField()
* 내용 컬럼
* created_date = models.DateTimeField(
default=timezone.now)
* 생성일자 컬럼
* published_date = models.DateTimeField(
blank=True, null=True)
* def publish(self):
* self.published_date = timezone.now()
* self.save()
* def __str__(self):
* return self.title
* tests.py
* views.py
- 장고에 등록하기