title: Is it possible to have an input from a form in a html template be added to the url in a django project?
body: <p>In the sidebar of my homepage, there is a search box where a user is meant to be able to type in the name of an entry and be taken to that page. So for example, if they type in <code>css</code> they would be taken to <code>http://127.0.0.1:8000/wiki/css</code> where the value inputted is appended to the url. (The home page url is <code>http://127.0.0.1:8000/wiki/</code>.)</p>
  <p>When I use the <code>get</code> method in the form it ends up searching up <code>/wiki/?q=css</code> instead of just having <code>/css</code> at the end of the url. However, when I use the <code>post</code> method in my form the url remains at <code>http://127.0.0.1:8000/wiki/</code> with no additional url at the end.</p>
  <p>How do I append an input to the end of a url?</p>
  <p>HTML:</p>
  <pre><code>&lt;h2&gt;Wiki&lt;/h2&gt;
  &lt;form action=&quot;/wiki/&quot; method=&quot;post&quot;&gt;
      {% csrf_token %}
      &lt;input class=&quot;search&quot; type=&quot;text&quot; name=&quot;q&quot; placeholder=&quot;Search Encyclopedia&quot;&gt;
  &lt;/form&gt;
  </code></pre>
  <p>urls.py:</p>
  <pre><code>from tokenize import Name
  from unicodedata import name
  from django.urls import path
  
  from django.http import HttpResponse
  
  from . import views
  
  urlpatterns = [
      path(&quot;&quot;, views.index, name=&quot;index&quot;),
      path('hello/', views.hello, name='hello'),
      path('&lt;str:name&gt;', views.entry, name='entry'),
      path('new/', views.new, name='new'),
      path('random/', views.randomEntry, name='random')
  ]
  </code></pre>
  <p>views.py:</p>
  <pre><code>from django.shortcuts import render
  from django.http import HttpResponse
  from django import forms
  import random
  
  from . import util
  
  
  def index(request):
      return render(request, &quot;encyclopedia/index.html&quot;, {
          &quot;entries&quot;: util.list_entries()
      })
  
  
  def hello(request):
      return HttpResponse('Hello, world')
  
  
  def entry(request, name):
      return HttpResponse(util.get_entry(name))
  
  
  def search(name):
      value = util.get_entry(name)
      if value != None:
          return value
  
  
  class searchForm(forms.Form):
      search = forms.CharField(label='Search Encyclopedia')
      # this was not used as I do not know if it would be useful
  
  
  def new(request):
      return render(request, &quot;encyclopedia/new.html&quot;, {
          &quot;entries&quot;: util.list_entries()
      })
  
  
  def randomEntry(request):
      list = []
      for i in util.list_entries():
          list.append(i)
      num = random.randint(0, len(list)-1)
      page = list[num]
      return render(request, f&quot;entries/layout.html&quot;, {
          &quot;entries&quot;: util.list_entries()
      })
  </code></pre>
  <p>util.py (I don't know if this is useful but it could be used):</p>
  <pre><code>import re
  from django.core.files.base import ContentFile
  from django.core.files.storage import default_storage
  
  
  def list_entries():
      &quot;&quot;&quot;
      Returns a list of all names of encyclopedia entries.
      &quot;&quot;&quot;
      _, filenames = default_storage.listdir(&quot;entries&quot;)
      return list(sorted(re.sub(r&quot;\.md$&quot;, &quot;&quot;, filename)
                  for filename in filenames if filename.endswith(&quot;.md&quot;)))
  
  
  def save_entry(title, content):
      &quot;&quot;&quot;
      Saves an encyclopedia entry, given its title and Markdown
      content. If an existing entry with the same title already exists,
      it is replaced.
      &quot;&quot;&quot;
      filename = f&quot;entries/{title}.md&quot;
      if default_storage.exists(filename):
          default_storage.delete(filename)
      default_storage.save(filename, ContentFile(content))
  
  
  def get_entry(title):
      &quot;&quot;&quot;
      Retrieves an encyclopedia entry by its title. If no such
      entry exists, the function returns None.
      &quot;&quot;&quot;
      try:
          f = default_storage.open(f&quot;entries/{title}.md&quot;)
          return f.read().decode(&quot;utf-8&quot;)
      except FileNotFoundError:
          return None
  </code></pre>