전체 글589 파이썬 Django for loop 파이썬 Django for loop for loop은 배열, 목록 또는 사전의 항목을 루프오버하는 것과 같이 시퀀스를 반복하는 데 사용된다. 목록의 항목을 순환한다: template.html {% for x in fruits %} {{ x }} {% endfor %} In views.py you can see what the fruits variable looks like. views.py from django.http import HttpResponse from django.template import loader def testing(request): template = loader.get_template('template.html') context = { 'fruits': ['Apple', 'Ban.. 2024. 3. 6. 파이썬 Django Operator-1 파이썬 Django 논리 연산자(Operator) : and 둘 이상의 조건이 참인지 확인한다. 2개의 논리값이 모두 참일 때 참 결과값을 반환한다. 둘 중에 하나의 논리값이 거짓일 경우에는 거짓을 반환한다. template.html {% if greeting == 1 and day == "Friday" %} Hello Weekend! {% endif %} In views.py you can see what the variables look like. views.py from django.http import HttpResponse from django.template import loader def testing(request): template = loader.get_template('template.. 2024. 3. 5. 파이썬 django if tag 파이썬 django if 문 if 문은 변수를 평가하고 값이 참이면 코드 블록을 실행한다. templates.html {% if greeting == 1 %} Hello {% endif %} In views.py you can see what the greeting variable looks like. views.py from django.http import HttpResponse from django.template import loader def testing(request): template = loader.get_template('template.html') context = { 'greeting': 1, } return HttpResponse(template.render(context, req.. 2024. 3. 4. 파이썬 Django 템플릿 태그(template tags) 파이썬 Django 템플릿 태그(template tags) Django 템플릿에서는 if 문과 루프를 실행하는 것과 같은 프로그래밍 로직을 수행할 수 있다. 이러한 키워드는 Django에서 "템플릿 태그"라고 한다. 템플릿 태그를 실행하려면 {% %}개의 괄호로 둘러싸야 한다. templates/template.html: {% if greeting == 1 %} Hello {% else %} Bye {% endif %} In views.py you can see what the greeting variable looks like. views.py from django.http import HttpResponse from django.template import loader def testing(reque.. 2024. 3. 3. 이전 1 ··· 3 4 5 6 7 8 9 ··· 148 다음