템플릿으로 html 불러오기
1. 서버 실행 - python manage.py runserver
2. 브라우저에서 localhost:8000으로 접속
3. HTML 소스보기
windows
- Internet Explore :
- 마우스 우클릭 - 소스보기
- Ctrl + U
- Chrome :
- 마우스 우클릭 - 페이지 소스보기
- 상단 메뉴바에 보기 - 소스 또는
- Ctrl+U
- Firefox :
- 마우스 우클릭 - 페이지 소스
- Ctrl + U
- Internet Explore :
OS X
- Safari : [Safari - 환경설정 - 고급 - 하단의 메뉴 막대에서 개발자용 메뉴 보기 체크] 필수
- 마우스 우클릭 - 페이지 소스보기
- Command + Option + I
- Chrome :
- 마우스 우클릭 - 페이지 소스보기
- 상단 메뉴바에 보기 - 개발자 정보 - 소스 보기
- Command + Option + U
- Firefox :
- 마우스 우클릭 - 페이지 소스
- Command + U
- Safari : [Safari - 환경설정 - 고급 - 하단의 메뉴 막대에서 개발자용 메뉴 보기 체크] 필수
4. 템플릿 추가하기
- 앱(elecetions) 폴더 아래에 templates 폴더 생성 (C\Code\mysite\elections\templates)
- templates 폴더 아래 elecetions 폴더 생성(C\Code\mysite\elections\templates\elections)
- elecetions 폴더 아래 index.html 파일 생성 (C\Code\mysite\elections\templates\elections\index.html)
- index.html 과 views.py 수정
<!-- C\Code\mysite\elections\templates\elections\index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>선거 후보</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<td><B>이름</B></td>
<td><B>소개</B></td>
<td><B>출마지역</B></td>
<td><B>기호</B></td>
</tr>
</thead>
<tbody>
<tr>
<td>가후보</td>
<td>후보입니다.</td>
<td>우리나라</td>
<td>기호1번</td>
</tr>
<tr>
<td>나후보</td>
<td>후보입니다.</td>
<td>우리나라</td>
<td>기호2번</td>
</tr>
<tbody>
</table>
</body>
# C\Code\mysite\elections\views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import Candidate
def index(request):
candidates = Candidate.objects.all()
return render(request, 'elections/index.html')
브라우저를 새로고침 하면 수정이 반영됩니다.
-
예제대로 했을 경우 오류가 납니다.
-
2018.6.14 14:52
1
-
render와 httpresponse의 차이가 뭔가요?
-
2018.2.27 21:03
0
-
강사님 목소리가 너무 작아요;;
-
2018.2.13 16:40
0
-
자바스크립트로 데이터 넣기
-
2017.10.8 23:33
1
-
UnicodeDecodeError
-
2017.1.7 14:59
1
-
UnicodeDecodeError 가 뜨면서 에러가 납니다.
-
2016.6.6 08:37
1
-
코딩하면 계속 오류가 납니다
-
2016.5.13 21:04
1
-
템플릿 불러오기 에러
-
2016.3.16 17:38
3