# Django validator error: 'list' object is not callable

**URL:** <https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243>\
**Category:** Forms & APIs\
**Created:** [April 18, 2022, 5:34pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243 "2022-04-18T17:34:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtbluedog](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mtbluedog/32/8184_2.png) [@mtbluedog](https://forum.djangoproject.com/u/mtbluedog)\
**Post date:** [April 18, 2022, 5:34pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243/1 "2022-04-18T17:34:18Z")

</div>

I’m trying to add a validator to a contact form in forms.py to prevent spammers from adding http:// and https:// links in the message.

I’ve included `from django.core.validators import RegexValidator` at the top of forms.py.

In the example below, when I use the general\_message form field and validators=, I get the error ' **list’ object is not callable.**

```auto
general_message = forms.CharField(label='General message*', required=True, widget=forms.Textarea, validators=[RegexValidator(regex=r'http(s)?|HTTP(s)?', message="No https allowed", code="invalid")] (
        attrs={'class': 'form-control', 'maxlength': '1000', 'rows': 8} ))

```

The example below of general\_message works fine when not using the validator:

```auto
general_message = forms.CharField(label='General message*', required=True, widget=forms.Textarea(
        attrs={'class': 'form-control', 'maxlength': '1000', 'rows': 8}
    ))

```

Any ideas?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 18, 2022, 5:51pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243/2 "2022-04-18T17:51:49Z")

</div>

> [@mtbluedog](#):
>
> ```auto
> widget=forms.Textarea, validators=[RegexValidator(regex=r'http(s)?|HTTP(s)?', message="No https allowed", code="invalid")] (
> attrs={'class': 'form-control', 'maxlength': '1000', 'rows': 8} ))
> 
> ```

You’ve got some parenthesis mixed up here. Notice where your `attrs` attribute is relative to the widget and validators attributes.

---

<div class="post-metadata">

**Author:** ![mtbluedog](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mtbluedog/32/8184_2.png) [@mtbluedog](https://forum.djangoproject.com/u/mtbluedog)\
**Post date:** [April 18, 2022, 6:55pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243/3 "2022-04-18T18:55:31Z")

</div>

Thanks, but I don’t see a difference in your code `widget=forms....` and mine. Am I missing something?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 18, 2022, 6:56pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243/4 "2022-04-18T18:56:55Z")

</div>

I copied what you had - the mistake is where you have the `validators` attribute relative to the widget attribute. Compare this **closely** to the version that you say works.

How is the `widget` defined in the working version? How is it defined in the not working version?

---

<div class="post-metadata">

**Author:** ![mtbluedog](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mtbluedog/32/8184_2.png) [@mtbluedog](https://forum.djangoproject.com/u/mtbluedog)\
**Post date:** [April 18, 2022, 8:10pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243/5 "2022-04-18T20:10:27Z")

</div>

Thanks, I edited my original question to show my original general\_message field that works and the general\_message field with the validator that throws the error.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 18, 2022, 8:23pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243/6 "2022-04-18T20:23:13Z")

</div>

Please post here, independently of what you’ve done before, _just_ the `widget` attribute definition of the working version, and of the non-working version.

---

<div class="post-metadata">

**Author:** ![mtbluedog](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mtbluedog/32/8184_2.png) [@mtbluedog](https://forum.djangoproject.com/u/mtbluedog)\
**Post date:** [April 19, 2022, 2:44pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243/7 "2022-04-19T14:44:51Z")

</div>

I don’t have a working version, other than a version that does not use the validator.

This is the non-working version:

```auto
general_message = forms.CharField(label='General message*', required=True, widget=forms.Textarea, validators=[RegexValidator(regex=r'http(s)?|HTTP(s)?', message="No https allowed", code="invalid")] (
        attrs={'class': 'form-control', 'maxlength': '1000', 'rows': 8} ))

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 19, 2022, 2:47pm UTC](https://forum.djangoproject.com/t/django-validator-error-list-object-is-not-callable/13243/8 "2022-04-19T14:47:07Z")

</div>

This is what I mean by my reference to “working version”:

> [@mtbluedog](#):
>
> The example below of general\_message works fine when not using the validator:
> 
> ```auto
> general_message = forms.CharField(label='General message*', required=True, widget=forms.Textarea(
> attrs={'class': 'form-control', 'maxlength': '1000', 'rows': 8}
> ))
> 
> ```

From these two versions, what is the `widget` attribute for each? I don’t want you to show the entire field definition, _only_ the widget definition.
