开发者

Django exception: Caught AttributeError while rendering: 'Order' object has no attribute 'get'

Apologies for the noob question. Also, seems like similar questions have been asked here already, however the answers are about initiating a form with request.POST, which isn't relevant to what I've run into.

So -

I have an Order model:

class Order(models.Model): <br/>
    tf = models.CharField(max_length=200)

And a corresponding form:

class OrderForm(ModelForm):
    class Meta:
        model = Order

A view for the Order object:

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,
        })

And, finally, the template:

<form action="" method="post">
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>

But When I place my browser at localhost:8000/process_order/1/ I get this error:

TemplateSyntaxError at /process_order/1/

Caught AttributeError while rendering: 'Order' object has no attribute 'get'

Reques开发者_运维问答t 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

Can anyone tell me what I am doing wrong? Or am I not supposed to use form.to_p with ModelForm?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜