repl.it
@misingnoglic/

factors with Jinja2 Template

Python

No description

fork
loading
Files
  • main.py
  • templates
  • dummy.py
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
from flask import Flask, render_template
import random
app = Flask(__name__)

def factors(num):
  return [x for x in range(1, num+1) if num%x==0]

@app.route('/')
def home():
  n = random.randint(2, 10000)
  return render_template(
    # name of template
    "index.html",
    # now we pass in our variables into the template
    random_num=n, 
  )

@app.route('/factors/<int:n>')
def factors_display(n):
	return render_template(
    # name of template
		"factors.html",
    # now we pass in our variables into the template
		number=n, 
		factors=factors(n) 
	)

if __name__ == '__main__':
    app.run(host='0.0.0.0')