I tried using jinja2

Last time: Continuation of Web application development using Flask.

Add routing

I will add a new routing to ʻapp.py` created last time.

app.py


from flask import Flask, render_template
app = Flask(__name__)

#Abbreviation

@app.route("/hello/<whom>")
def hello(whom):
  return render_template("hello.html", whom=whom)

<whom> is a variable, for example, if you access with / hello / taro, taro will be included in whom.

With return render_template ("hello.html", name = whom) , you can use it without hello.html by assigning the taro received from the routing to the variable name. I can do it.

Template file creation

Flask searches the templates folder for templates, so you need to create the directory templetes.

$ midir templates

Create hello.html in templetes.

hello.html


<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>Hello</title>
</head>
<body>
  <h1>Using Jinja2 Template engine</h1>
  <h2>Hello {{name}}</h2>
</body>
</html>

reference

Web application development "first step" with VS Code and Flask

Recommended Posts

I tried using jinja2
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using folium
I tried using folium
I tried using time-window
[I tried using Pythonista 3] Introduction
I tried using easydict (memo).
I tried face recognition using Face ++
I tried using Random Forest
I tried using Amazon Glacier
I tried using git inspector
[Python] I tried using OpenPose
I tried using magenta / TensorFlow
I tried using AWS Chalice
I tried using Slack emojinator
I tried using Rotrics Dex Arm # 2
I tried using Rotrics Dex Arm
I tried using GrabCut of OpenCV
I tried using Thonny (Python / IDE)
I tried server-client communication using tmux
I tried reinforcement learning using PyBrain
I tried deep learning using Theano
Somehow I tried using jupyter notebook
[Kaggle] I tried undersampling using imbalanced-learn
I tried shooting Kamehameha using OpenPose
I tried using the checkio API
[Python] I tried using YOLO v3
I tried asynchronous processing using asyncio
I tried scraping
I tried PyQ
I tried AutoKeras
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
I tried using Azure Speech to Text.
I tried using Twitter api and Line api
I tried playing a ○ ✕ game using TensorFlow
I tried using YOUTUBE Data API V3
[Kaggle] I tried ensemble learning using LightGBM
I tried using PyEZ and JSNAPy. Part 2: I tried using PyEZ
I tried to classify text using TensorFlow