@estraviz/

Multi-Page Flask Template

Python

Created by @a5rocks | Start building dynamic web pages using a minimal Python server framework called Flask with templates and dynamic pages

fork
loading
Files
  • main.py
  • templates
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, render_template, request
from random import choice

web_site = Flask(__name__)

number_list = [
    100, 101, 200, 201, 202, 204, 206, 207, 300, 301, 302, 303, 304, 305, 307,
    400, 401, 402, 403, 404, 405, 406, 408, 409, 410, 411, 412, 413, 414, 415,
    416, 417, 418, 421, 422, 423, 424, 425, 426, 429, 431, 444, 450, 451, 500,
    502, 503, 504, 506, 507, 508, 509, 510, 511, 599
]


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


@web_site.route('/user/', defaults={'username': None})
@web_site.route('/user/<username>')
def generate_user(username):
    if not username:
        username = request.args.get('username')

    if not username:
        return 'Sorry error something, malformed request.'

    return render_template('personal_user.html', user=username)


@web_site.route('/page')
def random_page():
    return render_template('page.html', code=choice(number_list))


web_site.run(host='0.0.0.0', port=8080)