hyeonga_code
파이선 웹구축_장고_08_테이블 생성_페이지 본문
- 테이블_페이지
1. 장고 실행
2. 앱 생성
3. <config> > 'urls.py'
'urls.py'
=====
1
2
3
4
5
6
7
|
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('함수이름/', include('앱이름.html'))
]
|
cs |
4. <앱이름> > 'views.py'
'views.py'
=====
1
2
3
4
5
6
|
from django.shortcuts import render
# Create your views here.
def 함수이름(request):
return render(request, '앱이름/참조파일.html')
|
cs |
5. <바탕폴더> > <templates> > <앱이름> > '참조파일.html' 생성
6. <config> > 'settings.py'
'settings.py'
=====
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'앱이름.apps.앱이름Config'
]
TEMPLATES = [
{
'DIRS': [BASE_DIR/'templates'],
}
]
|
cs |
7. <앱이름> > 'models.py'
'models.py'
1
2
3
4
5
6
7
8
9
10
11
|
from django.db import models
# Create your models here.
class 클래스이름(models.Model):
숫자변수 = models.IntegerField()
문자변수 = models.CharField(max_length=100)
문자열변수 = models.TextField()
def __str__(self):
return self.숫자변수
#_ 대표적으로 보일 변수를 설정
|
cs |
=====
8. 마이그레이션
=====
'''
(mysite) C:\Users\hyeon\mysite\06_if,for> python manage.py makemigrations
Migrations for '앱이름':
앱이름\migrations\0001_initial.py
- Create model 클래스이름
(mysite) C:\Users\hyeon\mysite\06_if,for> python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, 앱이름
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 sessions.0001_initial... OK
Applying 앱이름.0001_initial... OK
'''
>> <앱이름> > <migrations> > '0001_initial.py' 생성됨
- 테이블 생성된 것
9. '09_Admin 생성'
'Python_Django' 카테고리의 다른 글
파이선 웹구축_장고_10_Context_Http 테이블 정보 전달 (0) | 2023.06.02 |
---|---|
파이선 웹구축_장고_09_Admin생성 (0) | 2023.06.01 |
파이선 웹구축_장고_07_테이블 생성_터미널 (0) | 2023.05.30 |
파이선 웹구축_장고_06_URL_분리 (0) | 2023.05.29 |
파이선 웹구축_장고_05_URL_Render (0) | 2023.05.28 |