1👍
The reason you are getting the error is because you need to load the settings for django in order to use django’s configuration, models and tools. django provides the shell
management command which will load a Python prompt that is configured for django.
Run python manage.py shell
from the directory of your project (not of your application) and then you will not get that error (you’ll get a different one).
As you are learning django, don’t use MySQL as your database. Use the built-in sqlite database, as suggested in the tutorial to get up to speed on django.
- [Answer]-Django insert into list if doesn't contain it
- [Answer]-Storing uploaded dynamic media in Django
- [Answer]-Complex Ordering In Django with respect to related models
- [Answer]-Django: Handling several forms in one submit, using class based views?
0👍
If you take a look at your database configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': '1',
}
}
You have not set HOST
and PORT
. As your error states(not having all the required keys and their respective values will cause django to throw an error. In this case, HOST
and PORT
are requirements):
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
If you are developing on localhost, then your HOST
should be ''
and your PORT
should be 3306
which is the default for MySQL (unless you have changed this during the installation).
If you are new to django, try using SQLite, since it is the easiest to get started with. But if you chose to use SQLite, then you will have to enter a pathname in NAME
. Don’t worry if you have not created a SQLite .db
file. If none exits, it will create one for you.