[Web][Flask] Templates and Static files

 Templates and Static files

In web frameworks like Flask, files in the project are usually separated into two key categories: Template, Static Files.

Template (HTML)

  • Templates are HTML files that get dynamically rendered on the server.

  • They include logic like:

{{ variable }} – dynamic values from the backend

{% for %} / {% if %} – loops and conditions
  • These templates respond to requests and change based on user data or page logic.

  • Flask (Jinja), Django, Ruby on Rails (ERB), PHP, and others all treat HTML this way.

In Flask, templates are stored in the template_folder.


Static Files (CSS, JS, Images)

  • Static files are served as-is, without any server-side processing.

  • They include:

    • CSS files (e.g., style.css)

    • JavaScript files (e.g., ajax.js)

    • Assets like images, fonts, and icons

  • These don’t change depending on the request or user.

In Flask, static files are stored in the static_folder.

Comments