Django - Render view based on search query from search view
<p>I have what is probably a very basic question. I have read through <a href="https://docs.djangoproject.com/en/1.10/topics/forms/" rel="nofollow noreferrer">Django forms docs</a> but am still missing something here. I want to have a search bar in one template (<code>search.html</code>) and return the search query in another template (<code>results.html</code>). I have the following so far, using <a href="https://stackoverflow.com/questions/27300680/django-passing-a-variable-from-a-view-into-a-url-tag-in-template">this SO answer as a guide</a>, which returns the following error. Thanks for any help.</p>

<pre><code>Exception Value:    
results() missing 1 required positional argument: 'search_id'
</code></pre>

<p><strong>urls.py</strong></p>

<pre><code>urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^landing/', views.search, name='search'),
    url(r'^results/', views.results, name='results'),
]
</code></pre>

<p><strong>forms.py</strong></p>

<pre><code>from .models import Apartment
class Apt(forms.ModelForm):
  class Meta:
      model = Apartment
      fields = ('name')
</code></pre>

<p><strong>views.py</strong></p>

<pre><code>def search(request):
    if request.method == 'POST': #the form has been submitted
        form = Apt(request.POST) #bound form
        if form.is_valid(): #validations have passed
            name = form.cleaned_data['name']
            u = Apt.objects.create(name=name)
            #REST query will go here.

            #commit to database
            u.save()

            return redirect('results', search_id=u.name)

    else: #create an unbound instance of the form
        form = Apt(initial={'name':'name'})
    #render the form according to the template, context = form
    return render(request, 'search/landing.html', {'form':form})

def results(request, search_id):
    search_id = request.POST.get('name')
    query = get_object_or_404(Apt, pk=search_id)
    return render(request, 'search/results.html', {'query':query} )
</code></pre>

<p><strong>landing.html</strong></p>

<pre><code>{% extends "base_simple.html" %}

{% block title %}Look up your name{% endblock %}

{% block main_content %}

&lt;!-- Intro Header --&gt;
&lt;header class="intro"&gt;
    &lt;div class="intro-body"&gt;
        &lt;div class="container"&gt;
          &lt;div class="inner cover"&gt;
            &lt;h1 class="cover-heading"&gt;find your name&lt;/h1&gt;
            &lt;form id="searchform" method="POST" action="" accept-charset="utf-8"&gt;
            {% csrf_token %}
                &lt;input id="apt" type="text" class="form-control" placeholder="Apartment Name" value="{{ Apt.name }}"&gt;
                &lt;input type="submit" value="Search" class="btn btn-lg btn-default"&gt;
            &lt;/form&gt;
          &lt;/div&gt;            
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/header&gt;

{% endblock %}
</code></pre>

<p><strong>results.html</strong></p>

<pre><code>{% extends "base_simple.html" %}

{% block title %}search results{% endblock %}

{% block main_content %}

&lt;div class='col-sm-6 col-sm-offset-3'&gt;

&lt;div class="row"&gt;
    &lt;div class="col-sm-12"&gt;
        {% for q in query %}
        &lt;div class="jumbotron"&gt;
            &lt;h3&gt;{{ q.name }}&lt;/h3&gt;
        &lt;/div&gt;
        {% endfor %}    
    &lt;/div&gt;
&lt;/div&gt;
&lt;hr/&gt;

&lt;/div&gt;

{% endblock %}
</code></pre>