When someone registers your name and email I create a session and render the page with the name of who registered, but I can not understand how I do it so that the time I render the page again appears a modal .
views.py:
from django.shortcuts import render, redirect
from .models import *
from registrations.models import Group
def index(request):
form = NewsletterForm(request.POST or None)
group = Group.objects.filter(active=True).first()
show_modal = False
content = {'show_modal': show_modal, 'group': group, 'form': form}
if not group:
show_modal = True
content = {'show_modal': show_modal, 'form': form}
return render(request, 'index.html', content)
if form.is_valid():
contact = form.save()
request.session['contact_id'] = contact.id
request.session.set_expiry(100)
if 'contact_id' in request.session:
show_modal_contact = True
content = {'contact': contact, 'show_modal': show_modal, 'group': group, 'show_modal_contact': show_modal_contact}
return render(request, 'index.html', content)
content = {'contact': contact, 'show_modal': show_modal, 'group': group, 'show_modal_contact': show_modal_contact}
return render(request, 'index.html', content)
return render(request, 'index.html', content)
Modal that I want to appear when saving and rendering the page again:
<!-- Modal Contato -->
{% if show_modal_contact %}
<script type="text/javascript">
setTimeout(function(){
$(window).load(function(){
$('#modal_contato').modal('show');
});
}, 1000)
</script>
{% endif %}
{% if show_modal_contact %}
<div id="modal_contato" class="modal fade in" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="text-center bottom-border">
<img class="img-modal" src="{% static 'images/ilustra3.png' %}" />
</div>
<p class="text-modal text-center">Pronto, iremos te avisar assim que abrirem novas turmas</p>
<div class="text-center">
<a id="close_modal" class="btn btn-primary btn-estacao">Voltar para Estação Hack Teens</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endif %}
I even read something about AJAX and such, but I could not put it into practice, can you guys give me any more help?