+ -
当前位置:首页 → 问答吧 → 请教一个表单模板问题

请教一个表单模板问题

时间:2011-03-31

来源:互联网

本帖最后由 mirage_o 于 2011-04-01 10:34 编辑

我按照django book中写了一个表单模板,却不能在页面中显示,以下是代码:
forms.py
from django import forms;

TOPIC_CHOICES = (
    ('general','General enquiry'),
    ('bug','Bug report'),
    ('suggestion','Suggestion'),
)

class ContactForm(forms.Form):
    topic = forms.ChoiceField(choices=TOPIC_CHOICES);
    message = forms.CharField();
    sender = forms.EmailField(required=False);

views.py
def contact(request):
    return render_to_response('contact.html',{'form',ContactForm});


html:
<form action="." method="POST">
        <table> {{form.as_table}} </table>
        <p><input type="submit" value="Submit"></p>
        </form>

请问应该怎么修改才能在页面中显示表单模板中的内容
我用的是django1.2.5版本,似乎没有newforms,是不是在这个版本中已经集成到了django.forms?

作者: mirage_o   发布时间: 2011-03-31

自己搞定了,把views.py
改为
def contact(request):
    form = ContactForm();
    return render_to_response('contact.html',locals());
就行

作者: mirage_o   发布时间: 2011-04-01