default_if_none requires 2 arguments, 1 provided
Asked Answered
S

2

15

I used default_if_none as shown below:

<input type="text" name='username' value="{{ value|default_if_none: '' }}">

But, I got the error below:

django.template.exceptions.TemplateSyntaxError: default_if_none requires 2 arguments, 1 provide

So, how can I solve the error?

Sears answered 26/6, 2018 at 1:50 Comment(0)
H
50

You have an extra space which causes the error.

value="{{ value|default_if_none: '' }}"

should be

value="{{ value|default_if_none:'' }}"
Hijack answered 26/6, 2018 at 1:53 Comment(0)
T
0

With Django template filters, putting space either before or after : gets error as shown below:

                            # Space (Error)
                               ↓ ↓
value="{{ value|default_if_none : '' }}"

So, don't put any space there not to get error as shown below:

                         # No space (No error)
                              ↓ ↓
value="{{ value|default_if_none:'' }}"

In addition, putting space either before or after | doesn't get error:

            # Space (No error)
               ↓ ↓
value="{{ value | default_if_none:'' }}"
Tippets answered 25/6, 2023 at 23:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.