I have a form I am using for a drop down that I would like to stay on the 
page after submit is clicked. The problem is it disappears after submit. I 
would like the form drop down to still display after submit. I what it is 
after submit the form class isnt called again. How do I call the form class 
again?


urls.py
urlpatterns = [
    url(
        regex=r'ventris/$',
        view=views.ventrisselfservice,
        name='ventris'
        ),
    url(r'^ventrisselfservice', views.ventrisselfservice, name='ventris'),
    # url(r'^cran', views.cranselect, name='cranselect'),
    url(r'^ventrisviplookup', views.ventrisviplookup, 
name='ventrisviplookup'),
    url(r'^cran', views.CranSelect.as_view(), name='cranselect'),

view.py
def ventrisviplookup(request):
    cran = request.GET['cran']
    lb1, lb2 = cran_lb_lookup(cran)
    # print(lb1, lb2)
    ventris_vip1 = vip_full_configs(session, lb1)
    ventris_vip2 = vip_full_configs(session, lb2)
    # print('vip out', ventris_vip1)
    return render(request, 'cranselect.html', {'cran': cran,
                 'lb1': lb1, 'lb2': lb2, 'ventris_vip1': ventris_vip1, 
'ventris_vip2': ventris_vip2})


class CranSelect(FormView):
    model = CranSelect
    form_class = CranForm
    template_name = 'cranselect.html'

    def get(self, request, *args, **kwargs):
        form = self.form_class(request.GET or None)
        if form.is_valid():
            return self.form_valid(form)
        return self.render_to_response(self.get_context_data(form=form))

forms.py

class CranForm(forms.ModelForm):
    class Meta:
        model = CranSelect
        fields = ['cran']


template that calls the form
<div class="col-md-6">

        <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">Please select the CRAN area 
were you want to configure a Ventris VIP.</h3>
                    <div class="panel-body">
            <div class="form-group">
            <!-- <p>Please select the CRAN area were you want to configure 
a Ventris VIP.</p> -->
            <form id="sidebar" action="{% url 
'ventrisselfservice:ventrisviplookup' %}" id="cran_select" method="get">
                {% for field in form %}
                <div class="form-group">
                    <label class="control-label" for={{ form.as_p }}</label>

                </div>
                {% endfor %}
                <input type="submit" class="bottun" value="Submit"/>
            </form>
            </div>
        </div>
    </div>
</div>

template that displays the form

{% block content %}

    <h2>Ventris VIP Lookup </h2>

    <!-- <div class="container"> -->
{% include "cranselect_form.html" %}

        <!-- <div class="col-md-6"> -->

            {% if ventris_vip1 == "NoVIP" %}
            
            <h2>No VIPs in selected CRAN: {{cran}}</h2>
            <ul style="list-style-type:none">
            <li>{{lb1}} no vip</li>
            <li>{{lb2}} no vip</li>
            </ul>
            {% else %}




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f24969e-9b16-43e5-8cfb-650b58f779d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to