내용으로 건너뛰기
GaramX
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
현재 위치:
home
»
python
»
django
»
view
추적:
python:django:view
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== 뷰(view) ====== ===== views.py ===== <code python views.py> from django.shortcuts import render from django.views import generic # Create your views here. class index(generic.ListView): def __init__(self): self.title_nm = "메인페이지입니다." self.ogImgUrl = "" self.descript = "메인페이지입니다." self.template_name = "blog/index.html" def get(self, request, *args, **kwargs): self.content = {"descript":self.descript, "title_nm":self.title_nm, "ogImgUrl":self.ogImgUrl, "dataList":"[[[[ Hellow DJango ]]]]"} return render(request, self.template_name, self.content) </code> ===== polls/views.py ===== <code python polls/views.py> def index(request): # return HttpResponse("Hello, world! You're at the polls index.") latest_question_list = Question.objects.order_by('-pub_date')[:5] output = ', '.join([q.question_text for q in latest_question_list]) return HttpResponse(output) def detail(request, question_id): return HttpResponse("You're looking at question %s." % question_id) def results(request, question_id): response = "You're looking at the results of question %s." return HttpResponse(response % question_id) def vote(request, question_id): return HttpResponse("You're voting on question %s." % question_id) </code> ===== template ===== 프로젝트의 TEMPLATES 설정은 Django가 어떻게 템플릿을 불러오고 렌더링 할 것인지 기술합니다. 기본 설정 파일은 APP_DIRS 옵션이 True로 설정된 DjangoTemplates 백엔드를 구성합니다. 관례에 따라, DjangoTemplates은 각 INSTALLED_APPS 디렉토리의 《templates》 하위 디렉토리를 탐색합니다. <code python polls/templates/polls/index.html> {% if latest_question_list %} <ul> {% for question in latest_question_list %} <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li> {% endfor %} </ul> {% else %} <p>No polls are available.</p> {% endif %} </code>
python/django/view.txt
· 마지막으로 수정됨: 2025/04/15 10:05 저자
127.0.0.1
문서 도구
문서 보기
이전 판
역링크
맨 위로