Thursday, September 26, 2019

Conflicting settings import

I installed a pyhton package. The package requires django to display some
html pages. The thing is, I want to use this package in my django project.
However, one of the modules imports "from django.conf import settings from
django.template import Context, Template". This cause "RuntimeError:
Settings already configured". How can I make both settings that are imported
in my django project and the python package's work seamlessly?
I tried this, but it just causes more problems.
if not settings.configured:
settings.configure()


I understand that is code is configuring the django conf settings. Clearly,
this package has its own templates. How can I make sure that my templates
are still working while still allowing the template in the package are still
working too? Both are needed from my django project.

Link to part of the python package that is also importing
https://github.com/lambdamusic/Ontospy/blob/master/ontospy/ontodocs/builder.py
This is code from the python package that is causing the problem:
_dirname, _filename = os.path.split(os.path.abspath(__file__))
ONTODOCS_VIZ_TEMPLATES = _dirname + "/media/templates/"
ONTODOCS_VIZ_STATIC = _dirname + "/media/static/"

if StrictVersion(django.get_version()) > StrictVersion('1.7'):
from django.conf import settings
from django.template import Context, Template

settings.configure()
django.setup()
settings.TEMPLATES = [
{
'BACKEND':
'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
ONTODOCS_VIZ_TEMPLATES + "html-single",
ONTODOCS_VIZ_TEMPLATES + "html-multi",
ONTODOCS_VIZ_TEMPLATES + "markdown",
ONTODOCS_VIZ_TEMPLATES + "d3",
ONTODOCS_VIZ_TEMPLATES + "misc",
],
'APP_DIRS':
True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use
this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]

else:
from django.conf import settings
from django.template import Context, Template

*Is there a way to move all the template directories from the python package
and configure them in my django project settings.py?*



--
Sent from: http://python.6.x6.nabble.com/django-users-f58536.html

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1569534981175-0.post%40n6.nabble.com.

No comments:

Post a Comment