Django app giving me TypeError when trying to serve static files with Cloudinary

66 Views Asked by At

I am trying to use cloudinary to serve my django app static files. I'v been using Cloudinary to serve an store media file and it works pretty fine.
But when it gets to static files, I don't know what I am doing wrong.

here is the console error:

System check identified no issues (0 silenced).
July 04, 2023 - 14:05:06
Django version 4.1.5, using settings 'aesbegWebsite.settings'
Starting development server at http://127.0.0.1:7500/
Quit the server with CONTROL-C.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 157, in inner_run
    handler = self.get_handler(*args, **options)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 31, in get_handler
    handler = super().get_handler(*args, **options)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 78, in get_handler
    return get_internal_wsgi_application()
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/core/servers/basehttp.py", line 47, in get_internal_wsgi_application
    return import_string(app_path)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/utils/module_loading.py", line 15, in cached_import
    module = import_module(module_path)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbegWebsite/aesbegWebsite/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/core/handlers/wsgi.py", line 125, in __init__
    self.load_middleware()
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/core/handlers/base.py", line 61, in load_middleware
    mw_instance = middleware(adapted_handler)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/whitenoise/middleware.py", line 105, in __init__
    self.add_files(self.static_root, prefix=self.static_prefix)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/whitenoise/base.py", line 107, in add_files
    self.update_files_dictionary(root, prefix)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/whitenoise/base.py", line 119, in update_files_dictionary
    self.add_file_to_dictionary(url, path, stat_cache=stat_cache)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/whitenoise/base.py", line 130, in add_file_to_dictionary
    static_file = self.get_static_file(path, url, stat_cache=stat_cache)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/whitenoise/base.py", line 202, in get_static_file
    self.add_cache_headers(headers, path, url)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/whitenoise/base.py", line 223, in add_cache_headers
    if self.immutable_file_test(path, url):
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/whitenoise/middleware.py", line 177, in immutable_file_test
    static_url = self.get_static_url(name_without_hash)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/whitenoise/middleware.py", line 200, in get_static_url
    return staticfiles_storage.url(name)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/contrib/staticfiles/storage.py", line 173, in url
    return self._url(self.stored_name, name, force)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/contrib/staticfiles/storage.py", line 152, in _url
    hashed_name = hashed_name_func(*args)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/django/contrib/staticfiles/storage.py", line 401, in stored_name
    self.hashed_name(name, content=None, filename=intermediate_name)
  File "/home/z2phyrus/Desktop/websites/aesbeg-website/aesbeg_virtual_env/lib/python3.10/site-packages/cloudinary_storage/storage.py", line 284, in hashed_name
    content = open(absolute_path, 'rb')
TypeError: expected str, bytes or os.PathLike object, not NoneType

Hope anyone can help

I read all the documentation but cant seem to find the solution.

0

There are 0 best solutions below