""" WSGI config for config project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/ """ import os from pathlib import Path import ctypes import ctypes.util try: from dotenv import load_dotenv env_path = Path(__file__).resolve().parent.parent.parent / '.env' if env_path.exists(): load_dotenv(env_path) except ImportError: pass # --- WeasyPrint Library Preloading --- import traceback import sys import ctypes import ctypes.util lib_paths = [ '/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0', '/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0', '/usr/lib/x86_64-linux-gnu/libgobject-2.0-0.so', '/usr/lib/x86_64-linux-gnu/libfontconfig.so.1', '/usr/lib/x86_64-linux-gnu/libcairo.so.2', '/usr/lib/x86_64-linux-gnu/libpango-1.0.so.0', '/usr/lib/x86_64-linux-gnu/libpango-1.0-0.so', '/usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0', ] for path in lib_paths: try: ctypes.CDLL(path) except OSError: pass try: import weasyprint except Exception as e: error_msg = f"WeasyPrint Import Error: {str(e)}\n{traceback.format_exc()}" with open("/tmp/weasyprint_wsgi_error.log", "w") as f: f.write(error_msg) # ------------------------------------- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') from django.core.wsgi import get_wsgi_application application = get_wsgi_application()