As a Django user, I would like to read built-in docstrings for Django
classes without having an existing Django project.
When creating a new Django project, it can be helpful to read the built-in
docstrings for each class in a package before beginning. For example, if I
have never used django.db.models.PositiveIntegerField and want to know
what the "null" or "blank" kwargs do, I can open a Python or IPython REPL
and type the following:
{{{
from django.db import models
help(models.PositiveIntegerField)
}}}
The above, in theory, should print the help doc for the
PositiveIntegerField class. However, the current state of things causes a
traceback instead:
{{{
ImproperlyConfigured: Requested setting USE_I18N, but settings are not
configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing
settings.
}}}
According to the Django
[https://docs.djangoproject.com/en/4.0/topics/settings/#envvar-
DJANGO_SETTINGS_MODULE/ docs], this issue is caused by not telling Django
where your settings come from. However, if a user is just trying to read
generic documentation for a given class, I don't think they should have to
implement a concrete settings file first. Ideally, a user should be able
to read these docs locally without creating anything at all. I realize
that online documentation through the Django website is available, but it
would be nice to be able to read the docstrings in a REPL.
**Steps to Reproduce**
1. Create a new virtual environment (I use pipenv, but any should work)
2. Install django~=4.0.0 and ipython to your virtualenv
3. open the ipython REPL by running "ipython" from the command line
4. In the REPL, run the following 2 lines of code:
{{{
from django.db import models
help(models.PositiveIntegerField)
}}}
5. The above should result in a traceback ending with this error message:
{{{
ImproperlyConfigured: Requested setting USE_I18N, but settings are not
configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing
settings.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33536>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => wontfix
* component: Uncategorized => Database layer (models, ORM)
Comment:
Thanks for the feedback. This is caused by translatable class attributes
like `description = _("Positive integer")` which access the setting. I
don't see a feasible solution, but these classes don't have docstrings
anyway.
--
Ticket URL: <https://code.djangoproject.com/ticket/33536#comment:1>