Basically I would like a user to input a number in a field and the fibonacci result to be printed but once the input is inserted into the input field I recieve that it returned None instead of an object
I have this code over here for my html form:
{% block content %}
<form method="POST" action=".">{% csrf_token %}
<input type="text" name="fcal" value="{{F}}" />
<p>
<input type="submit" name="fibo" value="Fibonacci" />
</p>
</form>
{% if cal %}
Your Fibonacci answer is {{cal}}
{% endif %}
{% endblock %}
The content of my views.py is this one:
from django.shortcuts import render_to_response, get_object_or_404, render
from django.forms import ModelForm
from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpResponseNotFound
import fibonacci
def fibocal(request):
if request.method == 'POST':
fb = request.POST['fcal']
cal = fibonacci.fibo(fb)
return render(request, 'fibb/fibb.html', {'cal': cal})
else:
return render(request, 'fibb/fibb.html', {})
And my fibonacci function is this one:
def fibo(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
result = fibo(n - 1) + fibo(n - 2)
return result
I would like to know where the error is caused as I've looked again and again and I can see that I am returning a render not None
Full traceback include:
Traceback:
File "C:\python35\lib\site-packages\django\core\handlers\base.py" in get_response
158. % (callback.__module__, view_name))
Exception Type: ValueError at /fibb/
Exception Value: The view fibb.views.fibb didn't return an HttpResponse object. It returned None instead.
fibb
view. But you are showingfibo
. Show that view – karthikr