728x90
반응형

날짜 포맷

템플릿에서 날짜를 원하는 형식으로 가져오고 싶을때 👇

{{ board.start_date|date:'Y.m.d (D)' }}

 

날짜로 원하는 결과 가져오기

시작일이 현재 날짜보다 크거나 같고 종료일이 작거나 같은 경우만 불러오기

{% if board.start_date|date:'Ymd' <= time|date:'Ymd' and board.end_date|date:'Ymd' >= time|date:'Ymd' %}

 


 

board_list.html

<table class="table">
  <thead>
    <tr>
      <th>기간</th>
      <th>업체명</th>
      <th>직책</th>
      <th>이름</th>
    </tr>
  </thead>
  <tbody>
    {% for board in boards %}
    {% if board.start_date|date:'Ymd' <= time|date:'Ymd' and board.end_date|date:'Ymd' >= time|date:'Ymd' %}
    <tr onclick="location.href='/board/detail/{{ board.id }}'">
      <th>{{ board.start_date|date:'Y.m.d (D)' }} ~ {{ board.end_date|date:'Y.m.d (D)' }}</th>
      <th>{{ board.company }}</th>
      <th>{{ board.position }}</th>
      <th>{{ board.guest_name }}</th>
    </tr>
    {% endif %}
    {% endfor %}
  </tbody>
</table>

 


날짜 포맷 참고 사이트 👇

https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs 

 

Built-in template tags and filters | Django documentation | Django

Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate

docs.djangoproject.com

 

반응형

'Project > access-control' 카테고리의 다른 글

Python excel export(XlsxWriter)  (0) 2021.11.16
Django 템플릿 생성 순서(간단하게 정리)  (0) 2021.11.15
Django 한국어 설정  (0) 2021.11.11
admin 계정 생성  (0) 2021.11.10
마이그레이션  (0) 2021.11.09
복사했습니다!