-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with a django project #16
Comments
I guess you’d need to set the DJANGO_SETTINGS_MODULE environment variable, before running mkdocs? |
Okay, apparently I was stupid and while debugging changed my .env file...stupid me... Thanks for the help. |
🤷♂️ Sorry I don’t know - not something I’m really able to help with. |
see my edited answer |
hi @cw-intellineers @tomchristie where would you call django.setup()? because I have DJANGO_SETTINGS_MODULE filled but if:
Can you help me? I'm lost. Thanks |
So … I came across this, and ended up with a workaround I'm so ashamed of I'm starting to be proud of it. I created a file in docs/django_settings.py, which contains the settings I want to initialize with, as well as a call to django.setup() after said settings, and a dummy variable I called import os
import sys
docs_dir, _ = os.path.split(__file__)
sys.path.append(os.path.dirname(docs_dir))
SECRET_KEY = "."
INSTALLED_APPS = ["…"]
setup = None
import django # noqa
from django.apps import apps # noqa
from django.conf import settings # noqa
if not apps.ready and not settings.configured:
django.setup() I'm setting
So to fix that, django.setup() would have to be called as the first thing autodoc does, so that we don't cycle back to the code that called the setting; usually that is done in the entrypoint. But autodoc doesn't have an entrypoint… soooo, I made one by adding the following code to my index.md: <style type="text/css">
/* Hide the hack signature from the index. */
.autodoc { display: none; }
</style>
::: docs.django_settings.setup Now as one of the first things autodoc does (as part of the first document it processes), mkautodoc will import the docs.django_settings module, which will trigger django.setup() and avoid breakage later on. |
I am trying to incorporate mkautodoc to my project which is based on django and django-rest-framework. I believe before mkautodoc can properly work,
django.setup()
has to be called.Any advice on how to do this?
If I just include mkautodoc and try to create a docstring mkdocs crashes with:
django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
The text was updated successfully, but these errors were encountered: