0Pricing
Flask Academy · 강의

render_template과 templates 폴더

문자열 대신 HTML 파일을 반환합니다.

render_template과 templates 폴더은(는) CoddyKit의 무료 Flask Academy 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Flask Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Flask Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

From Strings to Pages

So far your routes returned plain strings. Real pages need HTML, and Flask gives you render_template to serve full HTML files cleanly.

What render_template Does

render_template finds an HTML file, runs it through the template engine, and returns the finished page as your response body.

from flask import render_template

@app.route('/')
def home():
    return render_template('index.html')

The templates Folder

Flask looks for your HTML in a folder named templates next to your app file. Put index.html there and Flask finds it automatically. 📁

myapp/
  app.py
  templates/
    index.html

Why a Fixed Name

The name templates is a convention, not a guess. Flask knows where to look, so you never write the folder path inside render_template.

Reference Only the Filename

You pass just the filename, not a full path. Flask joins it onto the templates folder for you, keeping your code short and portable.

return render_template('about.html')

Subfolders Inside templates

You can group pages in subfolders and reference them with forward slashes. This keeps a large project tidy as it grows.

return render_template('users/profile.html')

A Minimal Template

A template is ordinary HTML at heart. The simplest one is just a regular page with no special syntax yet.

<!doctype html>
<title>Home</title>
<h1>Welcome</h1>

Templates Get Rendered

Even a plain file is rendered: Flask processes it through Jinja2 first. That step is what lets you add dynamic pieces later.

Returning the Result

render_template returns a string of HTML, which you return from your view. Flask wraps it in a proper response with the right content type.

@app.route('/')
def home():
    return render_template('index.html')

TemplateNotFound Errors

If Flask cannot find the file, you get a TemplateNotFound error. Check the spelling and that the file truly sits inside templates.

Separating Logic and Markup

Templates keep HTML out of your Python. Views handle logic, templates handle presentation, and that split keeps both far easier to read.

Quick Check

Where does Flask expect your HTML files to live by default?

Recap

You learned that render_template serves HTML from the templates folder by filename, so logic stays in Python and markup stays in files. Nice work! 🎉

자주 묻는 질문

“render_template과 templates 폴더” 강의는 무료인가요?

네 — “render_template과 templates 폴더” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Flask Academy 강의 전체를 잠금 해제할 수 있습니다. Flask Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“render_template과 templates 폴더”에서 뭘 배우나요?

문자열 대신 HTML 파일을 반환합니다. 브라우저에서 직접 실행하는 실습 코드로 Flask Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Flask Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Flask Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“render_template과 templates 폴더” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Flask Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Flask Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. render_template과 templates 폴더
  2. 템플릿에 데이터 전달하기
  3. Jinja2 반복문과 조건문
  4. 자동 이스케이프와 safe 필터
← Flask Academy(으)로 돌아가기