By Matt S
I built a django app on my local machine, and then used this tutorial to deploy it with app platform (https://docs.digitalocean.com/tutorials/app-deploy-django-app/) The deployment was successful.
However, now when I try to run my django app locally to continue development, I’m getting the following error:
…/settings.py", line 95, in <module> raise Exception(“DATABASE_URL environment variable not defined”) Exception: DATABASE_URL environment variable not defined
Current settings in settings.py: DEVELOPMENT_MODE = os.getenv(“DEVELOPMENT_MODE”, “False”) == “True”
DEBUG = os.getenv(“DEBUG”, “False”) == “True”
I am unsure of how to reset my settings.py file so that it points to a local sqlite3 db for development.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
👋 @43e88fede83e446f9e392debd41d3c
Giving that tutorial a quick read over, it looks like you’ll need to set an environment variable to indicate that you’re in a development environment.
So in your dev env, set DEVELOPMENT_MODE=true.
This way the code will use a sqlite db instead of looking for a postgres instance, snippet from the tutorial:
if DEVELOPMENT_MODE is True:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
The dev env defaults to being disabled just above the snippet above:
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DEVELOPMENT_MODE = os.getenv("DEVELOPMENT_MODE", "False") == "True"
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.