@misingnoglic/

factors with Jinja2 Template

Python

No description

fork
loading
Files
  • main.py
  • templates
  • dummy.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.10925237627370366","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"ZnJvbSBmbGFzayBpbXBvcnQgRmxhc2ssIHJlbmRlcl90ZW1wbGF0ZQppbXBvcnQgcmFuZG9tCmFwcCA9IEZsYXNrKF9fbmFtZV9fKQoKZGVmIGZhY3RvcnMobnVtKToKICByZXR1cm4gW3ggZm9yIHggaW4gcmFuZ2UoMSwgbnVtKzEpIGlmIG51bSV4PT0wXQoKQGFwcC5yb3V0ZSgnLycpCmRlZiBob21lKCk6CiAgbiA9IHJhbmRvbS5yYW5kaW50KDIsIDEwMDAwKQogIHJldHVybiByZW5kZXJfdGVtcGxhdGUoCiAgICAjIG5hbWUgb2YgdGVtcGxhdGUKICAgICJpbmRleC5odG1sIiwKICAgICMgbm93IHdlIHBhc3MgaW4gb3VyIHZhcmlhYmxlcyBpbnRvIHRoZSB0ZW1wbGF0ZQogICAgcmFuZG9tX251bT1uLCAKICApCgpAYXBwLnJvdXRlKCcvZmFjdG9ycy88aW50Om4+JykKZGVmIGZhY3RvcnNfZGlzcGxheShuKToKCXJldHVybiByZW5kZXJfdGVtcGxhdGUoCiAgICAjIG5hbWUgb2YgdGVtcGxhdGUKCQkiZmFjdG9ycy5odG1sIiwKICAgICMgbm93IHdlIHBhc3MgaW4gb3VyIHZhcmlhYmxlcyBpbnRvIHRoZSB0ZW1wbGF0ZQoJCW51bWJlcj1uLCAKCQlmYWN0b3JzPWZhY3RvcnMobikgCgkpCgppZiBfX25hbWVfXyA9PSAnX19tYWluX18nOgogICAgYXBwLnJ1bihob3N0PScwLjAuMC4wJyk="},"asBuffer":null},"loaded":true}}
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')