django 1.10 render template html class
<p>After a user fills out a form on my site, I user render(request, html, context). I'd like to return the user to the same part of the page after they register. I am not using any front end frameworks (like angular - thats my next project). How would I go about doing this?</p>

<p>views.py:</p>

<pre><code>def homepage(request):
    countries = Country.objects.count()
    cities = City.objects.count()

    start_trip_date = date(xxxx, x, x)
    today = date.today()
    total_days = today - start_trip_date

    queryset_list = Post.objects.active()[:6]
    query = request.GET.get("q")
    if query:
        queryset_list = queryset_list.filter(
            Q(title__icontains=query) |
            Q(content__icontains=query) |
            Q(user__first_name__icontains=query) |
            Q(user__last_name__icontains=query)
        ).distinct()

    contact_form = EmailUpdatesForm(request.POST or None)
    if contact_form.is_valid():
        contact = contact_form.save(commit=False)
        contact.email = request.POST['email']
        contact.first_name = request.POST['first_name']
        contact.save()
        profile_data = {
            'email': contact.email,
            'first_name': contact.first_name,
        }

        plaintext = get_template('email/frontpage_registered_email/email_text.txt')
        htmly = get_template('email/frontpage_registered_email/email_template.html')
        text_content = plaintext.render(profile_data)
        html_content = htmly.render(profile_data)

        subject = "{0}, thank you for registering with xx!".format(contact.first_name)
        from_email = 'xx@gmail.com'
        to_email = contact.email

        msg = EmailMultiAlternatives(subject, text_content, from_email, [to_email])
        msg.attach_alternative(html_content, "text/html")
        msg.send()

        return render(request, "homepage/homepage.html", {})
    else:
        print contact_form.errors,

    context = {
        'object_list': queryset_list,
        'countries': countries,
        'cities': cities,
        'days_traveling': total_days.days,
        'contact_form': contact_form,
    }

    return render(request, "homepage/homepage.html", context)
</code></pre>

<p>and a made up html to show what I mean:</p>

<pre><code>&lt;body&gt;
&lt;div class="first"&gt;content&lt;/div&gt;
&lt;div class="second"&gt;
    &lt;form id="contact_form" method="POST" action="." enctype="multipart/form-data" novalidate&gt;
        &lt;fieldset&gt;
            {% csrf_toke %}
            {{ contact_form|crispy }}
            &lt;input class="btn..." type="submit" name="submit" value="Register" /&gt;
        &lt;/fieldset&gt;
    &lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
</code></pre>

<p>In the above I want to return the user to the div class="second".</p>

<p>Thanks you.</p>

<p>To do this, you need to differentiate the default GET request to access the page and the POST of the form. </p>

<p>E.g. You could do:</p>

<pre><code>contact_form = EmailUpdatesForm() 

if request.method == 'POST':
   contact_form = EmailUpdatesForm(request.POST)
   if contact_form.is_valid():
       contact = contact_form.save(commit=False)
       contact.email = request.POST['email']
       ....
       ....
       form_submit = True
</code></pre>

<p>and pass form_submit in the context. </p>

<p>Then, in HTML:</p>

<pre><code>{% if form_submit %}
   &lt;div class="second"&gt;&lt;/div&gt;
{% else %}
   &lt;div class="first"&gt;&lt;/div&gt;
{% endif %}
</code></pre>

python django django-templates django-email