Autosave: 20260211-123053
This commit is contained in:
parent
bf533af9e8
commit
d973c05c15
Binary file not shown.
@ -9,6 +9,8 @@ https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import ctypes
|
||||||
|
import ctypes.util
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
@ -18,6 +20,33 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
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
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||||
|
|||||||
Binary file not shown.
@ -37,7 +37,6 @@ from .forms import (
|
|||||||
)
|
)
|
||||||
from .utils import number_to_words_en, send_whatsapp_message, send_whatsapp_document
|
from .utils import number_to_words_en, send_whatsapp_message, send_whatsapp_document
|
||||||
from .views_import import *
|
from .views_import import *
|
||||||
from weasyprint import HTML
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -1406,6 +1405,7 @@ def get_pdf_context(obj, doc_type):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def generate_pdf_file(template, context, request):
|
def generate_pdf_file(template, context, request):
|
||||||
|
from weasyprint import HTML
|
||||||
html_string = render_to_string(template, context, request=request)
|
html_string = render_to_string(template, context, request=request)
|
||||||
base_url = request.build_absolute_uri('/')
|
base_url = request.build_absolute_uri('/')
|
||||||
return HTML(string=html_string, base_url=base_url).write_pdf()
|
return HTML(string=html_string, base_url=base_url).write_pdf()
|
||||||
|
|||||||
31
manage.py
31
manage.py
@ -14,6 +14,37 @@ def main():
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
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')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user