Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

python - Django html Check form type

I'm trying to build an html page in Django, where depending on the form passed the page will render different things. How can I know in the HTML the type of form passed?

I want to do something like this:

{% block content %}
    <div class="content-section container" >

            {% if form.type == 'ModelAForm' %}
                <div class="content-section">
                    <form method="POST" enctype="multipart/form-data">
                        {% csrf_token %}

                        {{ form.driver_color }}

                    </form>
                </div>
            {% endif %}

            {% if form.type == 'ModelBForm' %}
                <div class="content-section">
                    <form method="POST" enctype="multipart/form-data">
                        {% csrf_token %}

                        {{ form.driver_name}}

                    </form>
                </div>
            {% endif %}

    </div>
{% endblock content %}

On the {% if form.type == 'ModelAForm' %} how can I know the form type?

question from:https://stackoverflow.com/questions/65860247/django-html-check-form-type

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...