TIL Python Basics Day 56 - Rendering HTML/Static files and Using Website Templates



Rendering HTML templates



make a seperate directory 'templates'
Store index.html file,
and return render_template('index.html') in server.py
from flask import render_template

@app.route('/')
def home():
    return render_template('index.html')
if downloaded html file from web, it might be .htm -> change it to .html

Static files and Using Website Templates


static files needs to be inside static folder
static files: css, image, video files

1. image


specify directory in <td><img src="static/angela.png" alt="angela profile picture"></td>

2. css


create a css file in static file
main.css

body {
	background-color: purple
}
Link relationship to html at head part
index.html

<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}">
Note: browsers like to cache -> on the same day, it won't change over one day.
solution: hard reload -> shift + refresh button
キャッシュ
Webキャッシュは、一般的なドキュメントのコピーを自動的に保持するためのHTTPデバイスです.

Prebuilt Templates


https://html5up.net/
Change the directories accordingly -> ctrl + R for mass change
module 461 for Chrome developer tools for modifying on screen. After editing save the html and add it to your file.

Project. Digital Name Card

  • Downloaded html template from here
  • Changed SNS icons
  • Resized the image
    img {
    width: 100%;
    height: auto;
    }

  • I marked 70% progress in the online lecture. I've been studying for 60 days by myself. I've started it since January with 100 days challenge. My daily routine is very stable/uniform(is there any better expression for this?) I wake up around 8am and study till noon. Except for lunch, dinner and brief breaks, I try to focus on studying. It's not difficult with help of challengers application and time recording application. Since it's winter time now, It's perfect to stay in and focus on studying. I hope I can enjoy outdoor activities and socialising by this summer!