What is the correct way for deploying a Metronic-Django web application in a apache Debian server using mod-wsgi
Hi Yasniel Alejandro
Try update STATICFILES_DIRS in your settings: In your _keenthemes/settings.py, add the directory containing your SVG files to STATICFILES_DIRS. For example
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
os.path.join(BASE_DIR, "assets", "media", "icons"),
]
Hi
Sorry for the delay. Check that the application has the necessary permissions to read the SVG files in server. Look at the browser's console for any errors related to loading SVG icons.
To diagnose further, you might want to re-enable the SVG loading code and add some debugging to see where it might be failing. For example:
def getSvgIcon(path, classNames = "svg-icon", folder = "media/icons/"):
try:
svg_path = "." + KTTheme.asset(folder + path)
with open(svg_path, "r") as svg_file:
svg = svg_file.read()
output = "<span class="{}">{}</span>".format(classNames, svg)
except Exception as e:
output = "<span class="{}">Error: {}</span>".format(classNames, str(e))
return output
Hi, thank's for yor concern, i'm getting this error:
Error: [Errno 2] No existe el fichero o el directorio: './assets/media/icons/duotune/general/gen021.svg'
The archive exist and has access permissions
Hi Faizal
I've modify the method getSvgIcon of KTTheme class for testing and the project loads fine without svg icons
def getSvgIcon(path, classNames = 'svg-icon', folder = 'media/icons/'):
# Reference to current folder
#svg = open('.' + KTTheme.asset(folder + path)).read()
#output = '<span class="{}">{}</span>'.format(classNames, svg)
output = '<span class=""></span>'
return output
I guess I missed up some dependencies when install the project, any ideas??
Hi Yasniel Alejandro
Check the Import. Ensure that the KTBootstrapDefault class is correctly imported in your theme.py file. Check the function def setLayout
Check for layout path: KT_THEME_LAYOUT_DIR in _keenthemes/settings.py
After making any changes, restart the Apache server to apply the changes
Let me know if you need further assistance!
Hi
I have these configurations in my files:
_keenthemes/settings.py : KT_THEME_LAYOUT_DIR = 'layout'
_keenthemes/libs/theme.py :
from django.conf import settings
from pprint import pprint
import os
from django.templatetags.static import static
from importlib import import_module, util
import json
from django.core.cache import cache
def setLayout(view, context = {}):
KTTheme.htmlAttributes = {}
KTTheme.htmlClasses = {}
layout = os.path.splitext(view)[0]
layout = layout.split('/')[0]
# Get module path
module = '_templates.{}._bootstrap.{}'.format(settings.KT_THEME_LAYOUT_DIR.replace('/', '.'), layout)
# Check if the bootstrap file is exist
if not util.find_spec(module) == None:
# Auto import and init the default bootstrap.py file from the theme
KTBootstrap = KTTheme.importClass(module, 'KTBootstrap{}'.format(layout.title().replace('-', '')))
KTBootstrap.init(context)
else:
module = '_templates.{}._bootstrap.default'.format(settings.KT_THEME_LAYOUT_DIR.replace('/', '.'))
KTBootstrap = KTTheme.importClass(module, 'KTBootstrapDefault')
KTBootstrap.init(context)
return '{}/{}'.format(settings.KT_THEME_LAYOUT_DIR, view)
_keenthemes/templatetags/theme.py:
from django.utils.safestring import mark_safe
from django import template
from _keenthemes.libs.theme import KTTheme
from django.conf import settings
from pprint import pprint
Hi Yasniel Alejandro
You may refer to this docs about deployment Django project using Apache with wsgi
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/modwsgi/
Thank you
I've done all the hints described in the docs, but I'm getting these error
in apache log:
[wsgi:error] File "/var/www/.............../starterkit/_keenthemes/libs/theme.py", line 90, in getSvgIcon
[wsgi:error] 'Loading KTBootstrapDefault from _templates.layout._bootstrap.default'
I'm deploying in apache2 (Debian 12)