본문 바로가기

전체 글

(1836)
[Django]Dynamic URL-based Lookups CodingEntrepreneurs Django 강의 정리 장고 URL 요청 처리 방식> 1. Django는 사용할 루트 URLconf모듈을 결정합니다. 일반적으로 이 값은 ROOT_FLLCONF설정 값이지만 들어오는 경우HttpRequest개체에는(미들웨어에서 설정한) urlconf특성이 있으며, 해당 값은 ROOT_URLCONF설정 대신 사용됩니다. 2. Django는 Python모듈을 로드하고 변수를 찾습니다.urlpatterns. 이는 django.url.path()및/또는 django.urls.re path() 인스턴스의 시퀀스여야 합니다. 3. Django는 각 URL패턴을 순서대로 실행하고, 요청한 URL과 일치하는 첫번째 URL에서 path_info와 일치하도록 중지합니다. 4. URL패턴..
[Django] Model in a View CodingEntrepreneurs Django 강의 정리 view 처리 순서> query > database > data > django renders urls> """try_django URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-bas..
[Django]Model to Django Admin CodingEntrepreneurs Django 강의 정리 admin.py> 1. 자동 관리 인터페이스 2. 모델의 메타 데이터를 읽어 신뢰할 수 있는 사용자가 사이트의 컨텐츠를 관리할 수 있는 빠른 모델 중심 인터페이스 제공 3. 관리자의 권장 사용은 조직의 내부 관리 도구로 제한 admin.py> from django.contrib import admin from .models import BlogPost # Register your models here. admin.site.register(BlogPost) Django Shell> from blog.models import BlogPost obj = BlogPost.objects.get(title='Hello World') obj.title obj..
[Django]Save to the Database CodingEntrepreneurs Django 강의 정리 django shell> python manage.py shell argument X> from blog.models import BlogPost obj = BlogPost obj.title = 'This is my title' obj.content = 'This is my content' obj.save() Traceback (most recent call last): File "", line 1, in TypeError: save() missing 1 required positional argument: 'self' argument O> from blog.models import BlogPost obj = BlogPost() obj.title..
[Django]Your First App CodingEntrepreneurs Django 강의 정리 APP 생성> python manage.py startapp appname settings> # Application definition INSTALLED_APPS = [ # components "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", ] INSTALLED_APPS += [ "blog", ] app을 생성하고 settings - INSTALLED_APPS에 추가 해준다. 명시적으로 하기 위하여 위와 같..
[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..