Reputation: 1315
I am trying to print fibonacci series of a number using flask framework and jinja templates. The following program is giving me a 505 Internal server error! But when i comment the for loop inside the function,it gives me the correct result
fibonacciURL.py
from flask import Flask
from jinja2 import Environment, PackageLoader
app= Flask(__name__)
def fib(num):
if num==1 or num==0:
return num
else:
return fib(num-1)+fib(num-2)
@app.route('/fib/<number>')
def generate_fibonacci(number):
env= Environment(loader=PackageLoader('Fibonacci','templates'))
fibMap={}
#for x in range(number):
# fibMap[i]=fib(i)
for i in range(0,number):
print 'Hello'
#pass
template= env.get_template('table_template.html')
return template.render(num=3,map={1:1,2:2,3:3})
#return 'wda'
if __name__ =='__main__':
app.run(host='0.0.0.0')
my table_template.html is
<table>
{%for i in range(1,num)%}
<tr>
<td>{{i}}</td>
<td>{{map[i]}}</td>
</tr>
{% endfor %}
</table>
Without the for loop,the page is showing the expected result
Upvotes: 1
Views: 827
Reputation: 1121914
The route parameter <number>
is given to you as a string, not an integer.
If you want Flask to give you a numeric value, tell it so in the route configuration:
@app.route('/fib/<int:number>')
See the Variable Rules section in the quickstart.
Upvotes: 6