Conflicting settings import

7 views
Skip to first unread message

IWilliams

unread,
Sep 27, 2019, 7:05:03 AM9/27/19
to django...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages