• 회원가입
  • 로그인
  • 구글아이디로 로그인

[filters] Jinja - attr() 필터 - 객체의 속성 얻기. (= attr필터 = 어트르필터) ※ 속성만 조회

목차
  1. attr() 예제 - 객체의 속성 얻기
  2. attr() 정의
  3. attr() 구문

 

attr() 예제 - 객체의 속성 얻기

 

# python

user = User(username="John", age=30)


# template

{{ user | attr("username") }}

 


 

{% set hz = {'host': 'Homzzang.com', 'open': 2012} %}

 

{{ hz|attr("host") }} {{ hz|attr("open") }} {# 출력 X #}

{{ hz.host }} {{ hz.open }} {# 출력 O #}

{{ hz['host'] }} {{ hz['open'] }} {# 출력 O #}

{{ hz["host"] }} {{ hz["open"] }} {# 출력 O #}

 

 

attr() 정의

 

클래스 인스턴스인 객체의 속성을 얻는 필터.

 


 

1.

  • foo|attr("bar")는 foo.bar처럼 작동하지만 항상 속성이 반환되고 아이템이 조회되지 않음. 더 자세히 보기
  • 주의: key:value 쌍으로 구성된 dict 자료형이 아닌 클래스 인스턴스인 객체의 속성을 얻을 때만 사용함.

 

2. 공식 매뉴얼

https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.attr

 

 

attr() 구문

 

jinja-filters.attr(obj: Any, name: str)jinja2.runtime.Undefined | Any

 



분류 제목
sandbox Jinja - 샌드박스 - 보안 고려 사항 (Sandbox - Security Considerations)
sandbox Jinja - 샌드박스 - API (Sandbox - API)
sandbox Jinja - 샌드박스 - 연산자 가로채기 (Sandbox - Operator Intercepting)
python_types Jinja - 고유 파이썬 타입 - 예제들 (Native Python Types - Examples)
python_types Jinja - 고유 파이썬 타입 - API (Native Python Types - API)
template Jinja - 템플릿 - 개요 / 템플릿파일확장자 (Template - Synopsis / Template …
template Jinja - 템플릿 - 변수 (Template - Variables)
template Jinja - 템플릿 - 필터 (Template - Filters)
template Jinja - 템플릿 - 테스트 (Template - Tests)
template Jinja - 템플릿 - 주석 (Template - Comments)
template Jinja - 템플릿 - 공백 제어 ★ (Template - Whitespace Control)
template Jinja - 템플릿 - 회피처리 (Template - Escaping) ※ 진자 템플릿 코드를 문자 그대로…
template Jinja - 템플릿 - 라인 구문 (Template - Line Statements) ※ 약식 코드
template Jinja - 템플릿 - 템플릿 상속 ★★★ (Template - Template Inheritance)
template Jinja - 템플릿 - HTML 회피 (Template - HTML Escaping) ※ e필터 = 이필터
template Jinja - 템플릿 - 제어 구조 목록 ★★★ (Template - List of Control Struc…
template Jinja - 템플릿 - 컨텍스트 동작 가져오기 (Template - Import Context Behavi…
template Jinja - 템플릿 - 표현식 ★ (Template - Expressions) ※ (자료형/연산자/기호/키…
template Jinja - 템플릿 - 내장필터 목록 (Template - List of Builtin Filters)
template Jinja - 템플릿 - 내장테스트 목록 (Template - List of Builtin Tests)
2/9
목록
찾아주셔서 감사합니다. Since 2012