为noob问题道歉。此外,似乎已经在这里提出了类似的问题,但是答案是关于使用request.POST启动表单,这与我遇到的内容无关。
所以 -
我有订单型号:
class Order(models.Model): <br/>
tf = models.CharField(max_length=200)
以及相应的表格:
class OrderForm(ModelForm):
class Meta:
model = Order
订单对象的视图:
def process_order(request, pk):
p = get_object_or_404(Order, pk=pk)
form = OrderForm(p)
return render_to_response('mytest/process_order.html', {
'form': form,
})
最后,模板:
<form action="" method="post">
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
但是当我将浏览器放在localhost:8000 / process_order / 1 /我收到此错误时:
TemplateSyntaxError at /process_order/1/
Caught AttributeError while rendering: 'Order' object has no attribute 'get'
Request Method: GET
Request URL: http://localhost:8000/process_order/1/
Django Version: 1.3
Exception Type: TemplateSyntaxError
Exception Value:
Caught AttributeError while rendering: 'Order' object has no attribute 'get'
Exception Location: /home/ranmoshe/.virtualenvs/test/local/lib/python2.7/site-packages/django/forms/widgets.py in value_from_datadict, line 178
谁能告诉我我做错了什么?或者我不应该将form.to_p
与ModelForm一起使用?