from flask import Flask,render_template,request from fib_gen import fib_generator import logging logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.DEBUG) app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/fib',methods=['GET','POST']) def fib(): fibg = fib_generator() result = '' logging.debug(f'request.method={request.method}') if request.method == 'POST': element = request.form['element'] logging.debug(f'berechne Element:{element}') n= int(element) #formel= str(n-2) + '+' + str(n-1) formel = '' # Berechnungsformel initialisieren. if element != None: for i in range(n+1): fib = next(fibg) if i == n-2: # fib(n-2) zur Berechnungsformel dazu formel += str(fib) if i == n-1: # fib(n-1) mit + Zeichen zur Berechnungsformel dazu formel += '+' + str(fib) logging.debug(f'Fibonacci-Zahl: {fib}') logging.debug(f'formel={formel}') result=str(fib) elif request.method == 'GET': logging.debug('GET-Request') return render_template('index.html', result=result,formel=formel) if __name__ == '__main__': app.run(host='0.0.0.0',port=8085, debug=True)