初学者django:下一个按钮充当提交

时间:2012-03-03 17:24:27

标签: python html django

免责声明:我是python和django的新手,但已在Drupal编程

我正在开发一个基于Web的向导(就像在Microsoft Windows安装屏幕上一样),其中包含解释性文本,后跟上一个和下一个按钮(左右绿色箭头)。到目前为止,非常好。

但是,我当前的向导页面(在project.html中,由我的django apps views.py加载)现在使用一个表单(ModelForm的实例),它要求用户输入“项目”名称,例如My Project 。通常,这样的HTML表单会使用Submit按钮,但由于这是一个向导,我需要Next按钮作为Submit按钮,完全隐藏Submit按钮。此外,表单结束后会出现箭头图标。

你会怎么做?当然,我可以使用jquery,但有更好的pythonic或django方式吗?

一些代码:

#project.html
{% extends "base.html" %}
{% load i18n %}

<h3><span>{% trans 'Project details' %}</span></h3>
<p>{% trans 'What is the name of this project?' %}
    <form method="post" action=""> 
    {{ form.as_table }}
    <input type="submit" value="Submit"/>
    </form>
</p>
{% endblock %}

{% block buttonbar %}
<a href="/"><img src="/static/img/Button-Previous-icon-50.png" width="50" height="50" alt="Previous"><span>{% trans 'Previous' %}</span></a>
<a href="/profile"><img src="/static/img/Button-Next-icon-50.png" width="50" height="50" alt="Next button"><span>{% trans 'Next' %}</span></a>
{% endblock %}

谢谢!

2 个答案:

答案 0 :(得分:3)

<input type="submit" value="Next"/>

这会为您提供一个值为“Next”的按钮,该按钮充当提交按钮。如果这不是您想要的,请重新解释您的问题和/或举例说明按下后应采取的措施。

答案 1 :(得分:0)

您可能希望使用Django Form向导,在这种情况下:

https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/