diff --git a/config/__pycache__/wsgi.cpython-311.pyc b/config/__pycache__/wsgi.cpython-311.pyc index 1d0ee84..3595d64 100644 Binary files a/config/__pycache__/wsgi.cpython-311.pyc and b/config/__pycache__/wsgi.cpython-311.pyc differ diff --git a/config/wsgi.py b/config/wsgi.py index 6c87fb6..0b34d00 100644 --- a/config/wsgi.py +++ b/config/wsgi.py @@ -9,6 +9,8 @@ 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 @@ -18,6 +20,33 @@ try: except ImportError: pass +# --- FIX: Preload libraries for WeasyPrint/Pango --- +# Ensure LD_LIBRARY_PATH includes standard paths +if 'LD_LIBRARY_PATH' not in os.environ: + os.environ['LD_LIBRARY_PATH'] = '/usr/lib/x86_64-linux-gnu:/usr/lib' +else: + if '/usr/lib/x86_64-linux-gnu' not in os.environ['LD_LIBRARY_PATH']: + os.environ['LD_LIBRARY_PATH'] += ':/usr/lib/x86_64-linux-gnu' + +# Manually load the library +try: + if not ctypes.util.find_library('libgobject-2.0-0'): + # Try to load known paths directly + candidates = [ + 'libgobject-2.0.so.0', + '/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0', + '/usr/lib/libgobject-2.0.so.0' + ] + for c in candidates: + try: + ctypes.CDLL(c) + break + except OSError: + continue +except Exception: + pass +# --------------------------------------------------- + from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index da16869..47ba767 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/views.py b/core/views.py index 1692c35..af7e9bb 100644 --- a/core/views.py +++ b/core/views.py @@ -37,7 +37,6 @@ from .forms import ( ) from .utils import number_to_words_en, send_whatsapp_message, send_whatsapp_document from .views_import import * -from weasyprint import HTML from django.template.loader import render_to_string logger = logging.getLogger(__name__) @@ -1406,6 +1405,7 @@ def get_pdf_context(obj, doc_type): } def generate_pdf_file(template, context, request): + from weasyprint import HTML html_string = render_to_string(template, context, request=request) base_url = request.build_absolute_uri('/') return HTML(string=html_string, base_url=base_url).write_pdf() diff --git a/manage.py b/manage.py index 7dcd3e8..8fc5750 100755 --- a/manage.py +++ b/manage.py @@ -14,6 +14,37 @@ def main(): except ImportError: pass + # --- FIX: Preload libraries for WeasyPrint/Pango --- + # This fixes OSError: cannot load library 'libgobject-2.0-0' during deployment + import ctypes.util + import ctypes + + # 1. Ensure LD_LIBRARY_PATH includes standard paths (helper for find_library) + if 'LD_LIBRARY_PATH' not in os.environ: + os.environ['LD_LIBRARY_PATH'] = '/usr/lib/x86_64-linux-gnu:/usr/lib' + else: + if '/usr/lib/x86_64-linux-gnu' not in os.environ['LD_LIBRARY_PATH']: + os.environ['LD_LIBRARY_PATH'] += ':/usr/lib/x86_64-linux-gnu' + + # 2. Manually load the library to ensure it's available + try: + if not ctypes.util.find_library('libgobject-2.0-0'): + # Try to load known paths directly + candidates = [ + 'libgobject-2.0.so.0', + '/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0', + '/usr/lib/libgobject-2.0.so.0' + ] + for c in candidates: + try: + ctypes.CDLL(c) + break + except OSError: + continue + except Exception: + pass + # --------------------------------------------------- + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') try: from django.core.management import execute_from_command_line