[PYTHON] Load Django modules with an interpreter

(correction) If you run python manage.py shell, settings.py will be in the specified state, so it is better to use this. The following was a wasteful act.

======== Sometimes I want to import Django modules and see help and dir. At that time, if you do it normally, an import error will occur and the module cannot be loaded.

In [1]: import django.shortcuts
(...)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

In order to import it, you need to tell the module that describes the settings in the environment variable DJANGO_SETTINGS_MODULE. By default, you can specify settings.py directly under the Django project.

In [2]: import os
In [3]: os.environ['DJANGO_SETTINGS_MODULE'] = 'mokumoku.settings'
In [4]: import django.shortcuts
In [5]: help(django.shortcuts)

========

Recommended Posts

Load Django modules with an interpreter
Create an API with Django
Note: Send an email with Django
Browse an existing external database with Django
Create an update screen with Django Updateview
Internationalization with django
CRUD with Django
Authenticate Google with Django
Django 1.11 started with Python3.6
Upload files with Django
Procedure for creating an application with Django with Pycharm ~ Preparation ~
Development digest with Django
Output PDF with Django
Markdown output with Django
Use Gentelella with django
Twitter OAuth with Django
Getting Started with Django 1
Send email with Django
Deploy an existing app with docker + pyenv-virtualenv + uwsgi + django
File upload with django
Use LESS with Django
Pooling mechanize with Django
Use MySQL with Django
Start today with Django
LOAD DATA with PyMysql
Getting Started with Django 2
It's too easy to use an existing database with Django
I'm trying to create an authentication / authorization process with Django
Create an authentication feature with django-allauth and CustomUser in Django
Create a Todo app with Django ① Build an environment with Docker
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Load nested json with pandas
Get started with Django! ~ Tutorial ⑤ ~
Create an environment with virtualenv
Minimal website environment with django
Try an autoencoder with Pytorch
Do Django with CodeStar (Python3.8, Django2.1.15)
Deploy Django serverless with Lambda
Python3 + Django ~ Mac ~ with Apache
Getting Started with Python Django (1)
Creating an egg with python
Create a homepage with django
Get started with Django! ~ Tutorial ④ ~
Getting Started with Python Django (4)
Web application creation with Django
Getting Started with Python Django (3)
Combine FastAPI with Django ORM
Get started with Django! ~ Tutorial ⑥ ~
Debug with PEPPER python interpreter
Save tweet data with Django
Do AES encryption with DJango
Load test Websocket with Locust
Use django model from interpreter
Getting Started with Python Django (6)
Rename an existing Django application
Combine two images with Django
Getting Started with Django with PyCharm
Real-time web with Django Channels
Double submit suppression with Django
Django REST framework with Vue.js
Use prefetch_related conveniently with Django