3
votes

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.
1
Are you sure your code is not erroring out somewhere before the call to render? Could you edit your question and post the full traceback?André Borie
The error occurs only when I input a value in the input form and press the submit buttonh3k
can you add your code for the fibb view..Fermin Arellano
And fix your indentation; the error is very likely to be there.Daniel Roseman
the error is at fibb view. But you are showing fibo. Show that viewkarthikr

1 Answers

1
votes

In your views.py file, is there any fibb function that return a HTTPResponse? In the error trace, Django cannot find that response in fibb function in fibb.views. You can check the url directed to fibb function. Maybe it should be directed to fibocal function as you mentioned above.