title: Django: How to dynamically load form to current html page
body: <p>I have a simple form</p>
  
  <pre><code>class MyForm(forms.ModelForm):
  
  class Meta:
      model = Track
      fields = ['website', 'keyword']
      labels = {'website': 'Website URL', 'keyword': 'Keyword'}
  </code></pre>
  
  <p>and a view</p>
  
  <pre><code>def track(request):
  if request.method != 'POST':
      form = MyForm()
  else:
      form = MyForm(request.POST)
      if form.is_valid():
          form.save()
          return HttpResponseRedirect(reverse('tb_main:index'))    
  
  context = {'form': form}
  return render(request, 'tb_main/track.html', context)
  </code></pre>
  
  <p>and html form template(track.html)</p>
  
  <pre><code>&lt;form action="{% url 'tb_main:track' %}" method='post'&gt;
    {% csrf_token %}
    {% bootstrap_form form %}
  
   &lt;button name='submit'&gt;Submit&lt;/button&gt;
   &lt;input type='hidden' name='next' value="{% url 'tb_main:dashboard' %}" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I would like to be able to dynamically load the form when a user clicks on a button on the homepage without changing the url. I am assuming this could be accomplished using AJAX but I am not sure how to approach this.</p>
  
  <p>If i just do an AJAX call to track.html the view functionality won't come with it</p>
  
  <p>How can I dynamically load the view &amp; html template to the home page after a button click?</p>
  
  <p>I tried <code>&lt;button href="{% url 'tb_main:track' %}"&gt;load form&lt;/button&gt;</code></p>
  
  <p>but that doesn't work. Would be happy to hear from some of the more experienced developers on how to approach this. Thank you</p>