0

I would like to query using a HTML form from a template, for example: index.html, and render the data in a different template, results.html.

This was the solution for this same problem but in 2011 (I'm working with the newest version of Django so this is not working anymore)

  <form class="body_form"  method="GET" action="{% url 'results' 'var_name' %}" autocomplete="off">

      <input name="var_name" type="text">

Post: Django - is not a registered namespace

Is the syntax in the form field or in the input field right or this is an obsolet? I have the following error when I try this:

Reverse for 'results' with arguments '('var_name',)' not found. 1 pattern(s) tried: ['results']

views.py

def results(request,var_name):
    context = {'var': var_name,}
    return render(request, 'results.html', context)

urls.py

url(r'^results', results, name="results"),

Also, can I parse more than 1 variable using this method?

nourza
  • 2,215
  • 2
  • 16
  • 42
VicenteC
  • 311
  • 7
  • 26

1 Answers1

1

Your view expects var_name kwarg in URL, but you haven't provided. So, change your URL config as below,

url(r'^results/(?P&ltvar_name>[\w]+)/$', results, name="results"),

UPDATE-1

to pass the value to URL, change your template

action="{% url 'results' var_name=var_name %}"
JPG
  • 82,442
  • 19
  • 127
  • 206