웹 프로그래밍

    [Django Tutorial] Blog 만들기 (6)

    User 모델 Customization 1. models.py 에서 owner 설정 * on_delete가 CASCADE 방식이라는 의미는 외래키로 잡혀있는 User table에서 특정 레코드가 삭제되었을 때 그 레코드에 연결되어 있는 Post table의 레코드도 같이 삭제한다는 의미 class Post(models.Model): title= models.CharField(verbose_name='TITLE',max_length=50) #제목 description= models.CharField('DESCRIPTION', max_length=100, blank=True, help_text='simple description text.' )#요약 content= models.TextField('CONTE..

    [Django Tutorial] Blog 만들기 (5)

    Tag vue.js 작성전 3가지를 수정한다. 1. post table의 tags column 추가 2. post table의 owner column 추가 3. settings.py를 분리해서 개발용과 배포용으로 나눈다. * 블로그에 태그 기능을 개발하는 경우에 직접 개발할수도 있고 이미 나와있는 장고 패키지를 사용할 수도 있다. (구글에 django tag 검색하거나 djangopackages.org 에서 tag정도로 검색해보면 많음. 깃허브와 도큐먼트를 보고 사용해보자.) a. 설치 파이참 > File > Settings > Project > Python Interpreter > + > django-taggit 검색 > Install Package > OK (django taggit을 설치한 것은 s..

    [Django Tutorial] Blog 만들기 (4)

    폴더 위치에 대한 설명 django에서는 파일의 위치가 중요하다. 파일이 프로젝트 전체에 속한 것인지 앱 하나에 속한 것인지를 잘 구분해야한다. mysite 폴더를 프로젝트 dir, blog 폴더를 app dir, 최상단(backend 폴더)을 프로젝트 루트 dir or 프로젝트 베이스 dir 로 정의하였다. template dir도 2개가 있는데 루트 밑에 있는 dir을 프로젝트 템플릿 dir, app 밑의 dir를 앱 템플릿 dir로 정의하였다. 반면 models.py는 항상 특정 app에 속해야한다.

    [Django Tutorial] Blog 만들기 (3)

    urls.py mysite/urls.py from django.contrib import admin from django.urls import path from . import views from django.conf.urls import include urlpatterns = [ path('admin/', admin.site.urls), path('', views.HomeView.as_view(), name='home'), # 홈 패스 path('blog/', include('blog.urls')), # 블로그 패스 #from django.conf.urls import include 주의 ] blog/urls.py (생성해준다) * urlpatterns에 path() 넣어줄때 ctrl+space*2 하..

    [Django Tutorial] Blog 만들기 (2)

    모델 코딩 (models.py) Django에서는 모델이라는 파이썬 객체를 통해 데이터에 접속하고 관리한다. 모델: 저장된 데이터의 Schema를 정의한다. 모델은 models.py에서 정의되며 이들은 django.db.models.Model 을 상속받은 서브클래스로 구현된다. from django.db import models from django.urls import reverse class Post(models.Model): title= models.CharField(verbose_name='TITLE',max_length=50) #제목 description= models.CharField('DESCRIPTION', max_length=100, blank=True, help_text='simple ..

    [Django Tutorial] Blog 만들기 (1)

    Django skeleton 만들기 MVT 순서에 따라서 settings.py, (M) models.py, urls.py, (V) views.py, (T) templates 를 만든다. (1) Pycharm에 django 설치 File > settings > project: backend > python interpreter > + > django 검색 > Django install package > ok (2) Django-admin startproject mysite . (뒤에 . 꼭 붙여줘야함. 안하면 폴더가 한겹 더 생겨서 app만들때 manage.py 못찾는거같음) : mysite라는 디렉토리를 생성한다. (3) python manage.py startapp blog : blog 라는 이름의 앱..