Search code examples
pythondjangofavicon

500 internal server problem in Django issued from an inexistent favicon


I am a newbie in the Django world, and I am trying to start a new Django project but in vain! first of all, I have an old favicon from another project that appears. I don't have any referred favicon in this new project even I tried to add one it was the same problem.

During the handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/django/template/base.py", line 470, in parse
    compile_func = self.tags[command]
KeyError: 'endif'

During the handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/home/jihan/.local/lib/python3.8/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
    return self.application(environ, start_response)
  File "/home/user/.local/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
    response = self.get_response(request)
  File "/home/user/.local/lib/python3.8/site-packages/django/core/handlers/base.py", line 128, in get_response
    response = self._middleware_chain(request)
  File "/home/user/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 49, in inner
    response = response_for_exception(request, exc)
  File "/home/user/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 103, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/home/user/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 138, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/user/.local/lib/python3.8/site-packages/django/views/debug.py", line 52, in technical_500_response
    html = reporter.get_traceback_html()
  File "/home/user/.local/lib/python3.8/site-packages/django/views/debug.py", line 329, in get_traceback_html
    t = DEBUG_ENGINE.from_string(fh.read())
  File "/home/user/.local/lib/python3.8/site-packages/django/template/engine.py", line 136, in from_string
    return Template(template_code, engine=self)
  File "/home/user/.local/lib/python3.8/site-packages/django/template/base.py", line 155, in __init__
    self.nodelist = self.compile_nodelist()
  File "/home/user/.local/lib/python3.8/site-packages/django/template/base.py", line 193, in compile_nodelist
    return parser.parse()
  File "/home/user/.local/lib/python3.8/site-packages/django/template/base.py", line 472, in parse
    self.invalid_block_tag(token, command, parse_until)
  File "/home/user/.local/lib/python3.8/site-packages/django/template/base.py", line 531, in invalid_block_tag
    raise self.error(
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 8: 'endif'. Did you forget to register or load this tag?
[20/Apr/2023 11:22:30] "GET /favicon.ico HTTP/1.1" 500 59

this is my settings.py there's nothing special:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main.apps.MainConfig'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'

# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]

Solution

  • Since it's not very clear the problem I upgraded my Django version from 3.1 to 4.2 and now the problem disappeared. I do know if it's a version thing!