vidit
vidit

Reputation: 957

Django Unable to create model-based form: "str object not callable"

I am trying to create a form based on a model

urlpatterns = patterns('inventory.views',
    url(r'^template/create/$', CreateView.as_view(form_class='ItemTemplateForm', template_name='generic_form.html'), name='template_create'),

class ItemTemplateForm(forms.ModelForm):
    class Meta:
        model = ItemTemplate
        exclude = ('photos', 'supplies', 'suppliers')

This throws the error:

TypeError at /inventory/template/create/
'str' object is not callable
Request Method: GET
Request URL:    http://127.0.0.1:8000/inventory/template/create/
Django Version: 1.6
Exception Type: TypeError
Exception Value:    
'str' object is not callable
Exception Location: c:\Program Files (x86)\Python\lib\site-packages\django\views\generic\edit.py in get_form, line 44

I set a trace at the point the exception is thrown, but that didn't help either. What could be the reason of this error?

Upvotes: 1

Views: 456

Answers (1)

almalki
almalki

Reputation: 4775

I think in your urls you should pass the form class ItemTemplateForm, not the string name:

from app.form import ItemTemplateForm

urlpatterns = patterns('inventory.views',
    url(r'^template/create/$', CreateView.as_view(form_class=ItemTemplateForm, template_name='generic_form.html'), name='template_create'),

Upvotes: 2

Related Questions