본문 바로가기

Python_WEB

(436)
[Django]Built-In Template Tags CodingEntrepreneurs Django 강의 정리 {% if %} {% endif %}> 1. 해당 변수가 "참"이면(즉, 존재하고, 비어 있지 않고, 거짓 부울 값이 아닌 경우)블록의 내용을 실행한다. 가이드 {% for %} {% endfor %}> 1. 루프 가이드 home.html> {% extends "base.html" %} {% block content %} {{ title }} {{ request.user }} {{ request.path }} {{ user }} {{ user.is_authenticated }} {% if user.is_authenticated %} User Only data {% for a in my_list %} {{ a }} {% endfor %} {% en..
[Django]Template Context Processors CodingEntrepreneurs Django 강의 정리 request> TEMPLATES = [ { "OPTIONS": { "context_processors": [ "django.template.context_processors.request", ], }, }, ] 요청 구문 .user> TEMPLATES = [ { "OPTIONS": { "context_processors": [ "django.contrib.auth.context_processors.auth", ], }, }, ] 일반적으로 contrib.auth의 User 패키지로 설정된다. .path> 현재 URL 주소 user> 현재 로그인한 사용자 .is_authenticated> 사용자가 인증되었는지 확인 home.html> {% ext..
[Django]Rendering Any Kind of Template CodingEntrepreneurs Django 강의 정리 get_template> 1. 지정된 변수에 있는 파일명으로 템플릿을 로드하고 template 개체를 반환한다. 2. 반환 값의 정확한 유형은 템플릿을 로드한 백엔드에 따라 달라진다. 3. 템플릿을 찾을 수 없으면 TemplateDoesNotExist 에러를 반환한다. 4. 템플릿이 발견되었지만 잘못된 구문이 포함된 경우 TemplateSyntax/Error 에러를 반환한다. views> from django.http import HttpResponse from django.shortcuts import render from django.template.loader import get_template # Model View Template (MV..
[Django]Stay DRY with Templates CodingEntrepreneurs Django 강의 정리 {% extends "기초 HTML" %}> 1. 중복을 방지 2. 한 뭉치의 block들이 정의된 ‘base’라는 템플릿을 먼저 로드하고 뒤따르는 block들로 이 block들을 채운다. 3. 단일 파일(기본 템플릿)을 변경하여 사이트 재설계를 수행 {% block 변수명 %} {% endblock %}> 1. 하위 템플릿으로 재정의할 수 있는 블록을 정의 2. 중복을 방지 base.html> {{ title }} {% block content %} Replace this value {% endblock %} about.html> {% extends "base.html" %} {% block head_title %} About Us {% end..
[Django]Render Context in Templates CodingEntrepreneurs Django 강의 정리 format 출력 차이점> 1. Python 일반적 format my_title = "Title TEST" doc = "{title}".format(title=my_title) print(doc) 'Title TEST' 2. Django my_title = "Title TEST" django_render_doc = "{{ title }}".format(title=my_title) Title TEST views> from django.http import HttpResponse from django.shortcuts import render # Model View Template (MVT) def home_page(request): my_title..
[Django]Add Bootstrap CodingEntrepreneurs Django 강의 정리 bootstrap site> https://getbootstrap.com/ Bootstrap The most popular HTML, CSS, and JS library in the world. getbootstrap.com start template> Hello, world! hello_world.html> Hello, world! 적용 스크린샷>
[Django]Loading a HTML Template CodingEntrepreneurs Django 강의 정리 TEMPLATES 확인> python manage.py shell import os from django.conf import settings BASE_DIR = settings.BASE_DIR print(BASE_DIR) 'D:\\Code\\Study\\Try_DJANGO_TUTORIAL_Ver2.2' os.path.join(BASE_DIR, 'templates') 'D:\\Code\\Study\\Try_DJANGO_TUTORIAL_Ver2.2\\templates' 1. Django는 백엔드에 관계 없이 템플릿을 로드하고 렌더링 하기 위한 표준 API를 정의 2. 로드는 지정된 식별자에 대한 템플릿을 찾아 미리 처리하는 작업으로 구성 3. 일반..
[Django]Your First Template CodingEntrepreneurs Django 강의 정리 templates 폴더 생성> mkdir templates hello_world.html> Hello World render> 지정된 템플릿을 지정된 컨텍스트 사전과 결합하고 해당 렌더링 된 텍스트와 함께 GroupWise/Response개체를 반환 views> from django.http import HttpResponse from django.shortcuts import render # Model View Template (MVT) def home_page(request): return HttpResponse(request, "hello_world.html") def about_page(request): return HttpResponse..