Forums

Error in django template as : django.template.exceptions.TemplateSyntaxError

I got this error and it seemed error occured in django template. can anyone help me fix this error? my app recently have some errors that seems related to django version, as my django version is 3.2.12 and errors were about depricated functions in newer versions.Is it possible current Error also be related to this issue? this is complete error Traceback :

 2022-03-17 22:26:48,497: Internal Server Error: /
Traceback (most recent call last):
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 505, in parse
    compile_func = self.tags[command]
KeyError: 'ifequal'
**NO MATCH**
During handling of the above exception, another exception occurred:
**NO MATCH**
Traceback (most recent call last):
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/core/handlers/base.py", line 220, in _get_response
    response = response.render()
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/response.py", line 114, in render
    self.content = self.rendered_content
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/response.py", line 92, in rendered_content
    return template.render(context, self._request)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/backends/django.py", line 62, in render
    return self.template.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 175, in render
    return self._render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/loader_tags.py", line 208, in render
    return template.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 177, in render
    return self._render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/loader_tags.py", line 157, in render
    return compiled_parent._render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/loader_tags.py", line 63, in render
    result = block.nodelist.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/loader_tags.py", line 197, in render
    template = context.template.engine.select_template(template_name)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/engine.py", line 207, in select_template
    return self.get_template(template_name)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/engine.py", line 176, in get_template
    template, origin = self.find_template(template_name)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/engine.py", line 158, in find_template
    template = loader.get_template(name, skip=skip)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/loaders/cached.py", line 57, in get_template
    template = super().get_template(template_name, skip)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/loaders/base.py", line 28, in get_template
    return Template(
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 154, in __init__
    self.nodelist = self.compile_nodelist()
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 200, in compile_nodelist
    return parser.parse()
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 513, in parse
    raise self.error(token, e)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 511, in parse
    compiled_result = compile_func(self, token)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/defaulttags.py", line 854, in do_for
    nodelist_loop = parser.parse(
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 507, in parse
    self.invalid_block_tag(token, command, parse_until)
  File "/home/SocialAI/.local/lib/python3.8/site-packages/django/template/base.py", line 558, in invalid_block_tag
    raise self.error(
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 8: 'ifequal', expected 'empty' or 'endfor'. Did you forget to register or load this tag?
2022-03-17 22:26:49,255: OSError: write error

Which version of Django are you using? I see that ifequal tag has been removed in v. 4.0.

python version in web tab and my code is 3.8(web tab settings) but when check python and django version in bash console as "python3 -m django --version" i get "2.2.7 " and if run command "python -m django --version", result is "1.11.26". But if i check python versiondirectly i get "2.7.12"(bash console output).its strange!! my web app work fine with no error since a long time ago and this errors occured when i install django rest framework

python and pip are for Python 2.7. python3.6 and pip3.6 are for Python 3.6 etc. Make sure that you are using the pip that corresponds with the version of Python that you are using for your web app.

I don't have any problems with pip and i can install custom modules with command "pip3.8 install ---user xxx". as my python version is 3.8, i use pip3.8. are errors related to installing drf package?

What do you get when you run python3.8 -m django --version?

@giles, Sorry for late reply. i got "4.0.3" when run above command

So you need to remove the ifequal, ifnotequal tags in your code (with something like {% if a == b %}, {% if a != b %} respectively), or downgrade Django below v. 4.0.

I prefer to downgrade django to 3.8. how should do it? but why django version is 4 when in my webapp tab i choosed django 3.8?

There is no Django 3.8, so you will need to downgrade to 3.2.12 with pip3.8 install django==3.2.12

Since you appear to be confusing Python versions and Django versions, my guess would be that you chose Python 3.8 and not Django 3.8

Sorry, it's my fault. yes i chose python version 3.8 not django, but as described in forum, to install packages for current user without using virtual environment "--user" must used, so if i downgrade django by command " pip3.8 install django==3.2.12", isn't it downgrade django in pythonanywhere environment and cause to permission error?

And when i run that command plus --user it cause this error:

~ $ pip3.8 install --user django==3.2.12                                                                                                                                        
Looking in links: /usr/share/pip-wheels                                                                                                                                               
Collecting django==3.2.12                                                                                                                                                             
  Using cached https://files.pythonhosted.org/packages/9c/0e/02b7eff8fac2c25ede489933d4e899f6e6f283ae8eaf5189431057c8d406/Django-3.2.12-py3-none-any.whl                              
Requirement already satisfied: asgiref<4,>=3.3.2 in ./.local/lib/python3.8/site-packages (from django==3.2.12) (3.5.0)                                                                
Requirement already satisfied: pytz in /usr/lib/python3.8/site-packages (from django==3.2.12) (2019.3)                                                                                
Requirement already satisfied: sqlparse>=0.2.2 in /usr/lib/python3.8/site-packages (from django==3.2.12) (0.3.0)                                                                      
Installing collected packages: django                                                                                                                                                 
  Found existing installation: Django 4.0.3                                                                                                                                           
    Uninstalling Django-4.0.3:                                                                                                                                                        
      Successfully uninstalled Django-4.0.3                                                                                                                                           
  Rolling back uninstall of Django                                                                                                                                                    
  Moving to /home/SocialAI/.local/lib/python3.8/site-packages/Django-4.0.3.dist-info/                                                                                                 
   from /home/SocialAI/.local/lib/python3.8/site-packages/~jango-4.0.3.dist-info                                                                                                      
  Moving to /home/SocialAI/.local/lib/python3.8/site-packages/django/                                                                                                                 
   from /home/SocialAI/.local/lib/python3.8/site-packages/~jango                                                                                                                      
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/home/SocialAI/.local/bin/django-admin'                                                  
Check the permissions.

Why i get permission denied for django-admin?

Better use virtual environment.

My account is beginner and when i want use virtual environment and install custom packages in it,

[Errno 122] Disk quota exceeded happens. So if i get required packages list by "pip freeze" command and then delete folder "site-packages" to free disk space and then install all packages in virtual environment again, is it ok?

Possibly, virtualenvs take a little more space than simply installing with --user, so if you're really close to the limit without the virtualenv, you may go over with it.

Finally i figured to create a virtual environment and install django 3.2.12 and custom packages in it, but after all i encounter a new error in sqlit3 backend as bellow. as in my local version of my site, django version is 3.0.6 i install this django for test, but error still exist.

Internal Server Error: /
Traceback (most recent call last):
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/views/generic/base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/views/generic/list.py", line 157, in get
    context = self.get_context_data()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/plans/views.py", line 120, in get_context_data
    context['plan_table'] = self.get_plan_table(self.object_list)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/plans/views.py", line 74, in get_plan_table
    for plan in plan_list:
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 276, in __iter__
    self._fetch_all()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 1263, in _fetch_all
    self._prefetch_related_objects()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 782, in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 1651, in prefetch_related_objects
    obj_list, additional_lookups = prefetch_one_level(obj_list, prefetcher, lookup, level)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 1764, in prefetch_one_level
    prefetcher.get_prefetch_queryset(instances, lookup.get_current_queryset(level)))
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 635, in get_prefetch_queryset
    for rel_obj in queryset:
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 276, in __iter__
    self._fetch_all()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 74, in __iter__
    for row in compiler.results_iter(results):
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1095, in apply_converters
    value = converter(value, expression, connection)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/backends/sqlite3/operations.py", line 286, in converter
    return create_decimal(value).quantize(quantize_value, context=expression.output_field.context)
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

That sounds like a good question for Stack Overflow -- if you post there with the exception stack trace, and the code that you're using to create the models used in the view that is generating that error, someone will likely be able to help you.

Thanks for your advice, but as this error occured in package codes (plans and sqlite3) and not my codes, and also local version of my app still work fine, why this error occured? Actually i don't change anything in my codes, and only unexpected django upgrade to ver 4 happened. So it seems this error maybe relate to current changes in my settings!

Good point about your own code not appearing in the stack trace. Yes, that sounds likely. Do you have exactly the same settings.py locally and on PythonAnywhere?

My settings.py actually is same locally and on PythonAnywher, but my purpose of

So it seems this error maybe relate to current changes in my settings!

isn't about changes in setting.py file, is about uninstalling all custom packages and installing them again in virtual environment and changes i made in web app setup to make app use virtual environment.

Maybe it would make sense to delete and then completely re-build the virtualenv? Perhaps the changes that you made earlier that upgraded Django to 4.0.x pulled in other changes that are incompatible with your code.

Maybe, i will try it

Let us know if it worked. That may help other people with the same problem.

I delete virtualenv and rebuild it again but same error occured. It's so strange for me!

I have seen some stuff about Django not working with older versions of sqlite. You could try upgrading your system image to see if that helps.

@glenn I figured that error by some test modification in plans code (views.py) and a new error occured as bellow:

   Traceback (most recent call last):
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/core/handlers/base.py", line 204, in _get_response
    response = response.render()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/loader_tags.py", line 183, in render
    template = context.template.engine.select_template(template_name)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/engine.py", line 174, in select_template
    return self.get_template(template_name)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/engine.py", line 143, in get_template
    template, origin = self.find_template(template_name)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/engine.py", line 125, in find_template
    template = loader.get_template(name, skip=skip)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/loaders/cached.py", line 58, in get_template
    template = super().get_template(template_name, skip)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/loaders/base.py", line 29, in get_template
    return Template(
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 155, in __init__
    self.nodelist = self.compile_nodelist()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 193, in compile_nodelist
    return parser.parse()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 478, in parse
    raise self.error(token, e)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 476, in parse
    compiled_result = compile_func(self, token)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/loader_tags.py", line 278, in do_extends
    nodelist = parser.parse()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 478, in parse
    raise self.error(token, e)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 476, in parse
    compiled_result = compile_func(self, token)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/defaulttags.py", line 1094, in load
    lib = find_library(parser, name)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/defaulttags.py", line 1039, in find_library
    raise TemplateSyntaxError(
django.template.exceptions.TemplateSyntaxError: 'plan_custom_tags' is not a registered tag library. Must be one of:
RuleManager_filters
admin_list
admin_modify
admin_urls
cache
i18n
jalali_tags
l10n
log
rest_framework
static
tz

and say 'plan_custom_tags' is not a registered tag library. as described in django documentation template tags must defined in templatetags directory in root of application, and in plan root directory there wasn't any 'templatetas ' directory. It's so strange! why this error occured? Then for testing i manually create that directory as described in django doc and error disappeared, but new error occured as bellow:

    2022-04-05 18:52:35,917: Internal Server Error: /
Traceback (most recent call last):
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/core/handlers/base.py", line 204, in _get_response
    response = response.render()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/loader_tags.py", line 195, in render
    return template.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 172, in render
    return self._render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/loader_tags.py", line 195, in render
    return template.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 172, in render
    return self._render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/template/defaulttags.py", line 171, in render
    len_values = len(values)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 262, in __len__
    self._fetch_all()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 1326, in _fetch_all
    self._prefetch_related_objects()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 813, in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, *self._prefetch_related_lookups)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 1730, in prefetch_related_objects
    obj_list, additional_lookups = prefetch_one_level(
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 1855, in prefetch_one_level
    prefetcher.get_prefetch_queryset(instances, lookup.get_current_queryset(level)))
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 637, in get_prefetch_queryset
    for rel_obj in queryset:
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 280, in __iter__
    self._fetch_all()
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 1324, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/query.py", line 68, in __iter__
    for row in compiler.results_iter(results):
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1122, in apply_converters
    value = converter(value, expression, connection)
  File "/home/SocialAI/.virtualenvs/expertenv/lib/python3.8/site-packages/django/db/backends/sqlite3/operations.py", line 313, in converter
    return create_decimal(value).quantize(quantize_value, context=expression.output_field.context)
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

Same Error again! As you advised i upgrade my system image to latest and nothing changed.

Did you rebuild your virtualenv after changing system image?

It's very disappointing situation!

@fjl I rebuild virtualenv and same error occured!!My webapp was running without any problems, until the problem of unwanted django upgrade occurred and after that all these problems occurred spontaneously. Is there no real solution?

It looks like a general Django issue -- it's hard to debug without knowing your code. How doeas look the code for plan_custom_tags which, I understand, you created?

@pafk It was for testing only and now i deleted that code, indeed i found there was a {% load custom_plan_tags%} in one of my templates(Since my app works with no error) and cause that error related to plan_custom_tags. Now, after remaking virtualenv i delete that load command and that error disappeared, but last error i posted earlier occured again.

And you have permit to see all of my code if it help to debug.

We don't have resources to read your whole code and debug it -- maybe you should look for help on Django-related forums? The error you're getting is related to conversions to Decimal and, if I'm reading the traceback correctly, it happens in the templates.

Thanks for anybody replied and tried to help me. If i solve this error i will inform maybe it help anothers

Finally i found the solution and it was presaved records in database! So by deleting related records in datbase problem solved. Just enabling "DEBUG=True" in app setting was required to control which data and value passed to functions

Excellent! Glad you found the solution and thanks for sharing!