Closed nbensa closed 2 years ago
Yeah, I can see how that would be confusing.
It is, however, correct Python (hence my change to the title of the issue). It just assumes that someone's already defined DATABASES
-- which is not common, but not super uncommon either. For example, something like this is fairly typical:
DATABASES = {'default': {'engine': 'django.db.backends.sqlite3', 'name': 'something.db'}}
# ... later ...
if 'DATABASE_URL' in os.environ:
DATABASES['default'] = dj_database_url.config()
Nevertheless, the example should probably be a bit more clear (or contain both versions). If you'd like to work up a PR I'd love to review it!
@jacobian I can make a PR for that.
For clarity I'd simply replace what's currently in the README with @nbensa's "Correct code". Someone who's already defined DATABASES
should be able to follow along. I'm okay with @ParthS007's solution, too, either is an improvement.
Raises:
Correct code should be: