Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting an error didn't return an HttpResponse object. What is going on?
    text
    copied!<p>For the first time i am trying to create a small django application. It is just a basic page with two forms, a search form, which returns values from a database (working well), and a insert form (the problem). In the insert form there are three text fields asking for values for a new row in the database. The app is called "searcher". Here is my code:</p> <p>views.py</p> <pre><code>from django.http import HttpResponse from django.template import Context from django.template.loader import get_template from searcher.models import Publisher from django.db.models import Q def search(request): if "search" in request.GET: value = request.GET['search'] results = Publisher.objects.filter(Q(city__contains=value) | Q(name__contains=value)) else: value = "No term" results = [] template = get_template("base.html") html = template.render(Context({"value":value, "results":results})) return HttpResponse(html) def insert(request): if "name" in request.POST: for key in request.POST: counter = 0 if key != '': counter = counter + 1 if counter == len(request.POST): row = Publisher(name=request.POST['name'], city=request.POST['city'], website=request.POST['website']) row.save() </code></pre> <p>base.html</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form method = "GET" action = ""&gt; &lt;input type = "text" name = "search"&gt;&lt;input type = "submit"&gt; &lt;/form&gt;&lt;br&gt; you searched for:{{value}}&lt;br&gt; your results: {% for result in results %} &lt;br&gt;{{result}}&lt;br&gt; {% endfor %} &lt;br&gt;&lt;br&gt; &lt;form method = "POST" action = "/test/insert/"&gt; &lt;input type = "text" name = "name" value = "name"&gt;&lt;br&gt; &lt;input type = "text" name = "city" value = "city"&gt;&lt;br&gt; &lt;input type = "text" name = "website" value = "website"&gt;&lt;br&gt; &lt;input type = "submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>urls.py </p> <pre><code>from django.conf.urls import patterns, include, url from searcher import views urlpatterns = patterns('', url(r'^test/$', views.search), url(r'^test/insert/$', views.insert), ) </code></pre> <p>the error is saying "ValueError at /test/insert The view searcher.views.insert didn't return an HttpResponse object." as a result of me submitting the insert form.</p> <p>I understand what the error is saying: sorry but all views in views.py MUST return something to show.</p> <p>Firstly why is this?</p> <p>And secondly what is the correct way to accomplish the insert form ? Currently i have set the form action = "/test/insert/" so that in urls.py it can recognise the insert form was submitted and call the function insert, how should the function be called instead?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload