Reputation: 35
I'm trying to render a form through a templatetag in django so that I can I can render the form on multiple pages. However, I get the following error when I try to render it:
_ init_() takes at least 2 arguments (1 given).
This arises, I believe, from the templatetag not passing the user information to the form. The authenticated user should be the user passed to the form.
Forms.py:
class ExpressionForm(forms.ModelForm):
class Meta(object):
model = Expression
exclude = ('user',)
body = forms.CharField(widget=forms.Textarea(attrs={'rows': 2, 'cols': 19}), required=False, label=_('Body'))
def __init__(self, user, *args, **kwargs):
super(ExpressionForm, self).__init__(*args, **kwargs)
self.fields['expressiontype'].queryset = ExpressionType.objects.all()
self.fields['expressiontype'].required = True
And in my templatetag .py:
@register.inclusion_tag('expressions/templatetags/express.html')
def express():
return {'form': ExpressionForm()}
How would I go about passing the user to the form through the templatetag? Thanks :)
Upvotes: 1
Views: 1085
Reputation: 174614
The documentation details how to pass arguments into custom tags.
Your other option is to adjust your tag so it is aware of the context.
Upvotes: 1