On May 7, 1:48 am, Ricko <rickentr...@gmail.com> wrote:
> Hi All,
>
> Bashing my head against a wall trying to understand this issue.
> Playing around with Django-Contact-Form app, and trying to use my own
> subclassed Form in the views. From the code in views, it looks like it
> just takes an optional arg, form_class, which can be your Form
> subclassed from ContactForm. Here is my Form class:
>
> from contact_form.forms import ContactForm
> from django import forms
>
> attrs_dict = { 'class': 'required' }
>
> class EnhancedContactForm(ContactForm):
>
>         def __init__(self, data=None, files=None, request=None, *args,
> **kwargs):
>                 super(EnhancedContactForm, self).__init__(request, *args, 
> **kwargs)
>
> I know it doesn't do anything, was just trying to get the simplest
> form to work first. Here is my urls.py:
>
> urlpatterns += patterns('',
>                        url(r'^contact/$',
>                            contact_form,
> {'form_class':EnhancedContactForm},
>                            name='contact_form'),
>                        url(r'^contact/sent/$',
>                            direct_to_template,
>                            { 'template': 'contact_form/
> contact_form_sent.html' },
>                            name='contact_form_sent'),
>                        )
>
> It fails with the stack:
>
> TemplateSyntaxError: Caught an exception while rendering: unbound
> method __unicode__() must be called with EnhancedContactForm instance
> as first argument (got nothing instead)
>
> Original Traceback (most recent call last):
>   File "/Library/Python/2.5/site-packages/django/template/debug.py",
> line 71, in render_node
>     result = node.render(context)
>   File "/Library/Python/2.5/site-packages/django/template/
> defaulttags.py", line 155, in render
>     nodelist.append(node.render(context))
>   File "/Library/Python/2.5/site-packages/django/template/debug.py",
> line 87, in render
>     output = force_unicode(self.filter_expression.resolve(context))
>   File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
> line 71, in force_unicode
>     s = unicode(s)
> TypeError: unbound method __unicode__() must be called with
> EnhancedContactForm instance as first argument (got nothing instead)
>
> If you substitute the standard ContactForm in urls.py, it fails the
> same way.
>
> Anyone seen this before? What am I doing wrong?
>
> Cheers
> Ricko

The only issue I can see is that your overridden __init__ method
accepts the data and files arguments, but doesn't pass them onto the
superclass. Not sure if that would cause the error you're seeing -
looks like you've run into the Django bug that swallows your actual
exception - but it would be worth changing your super call to:

    super(EnhancedContactForm, self).__init__(request, data, files,
*args, **kwargs)

--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to