Question

Local database throws an error after adding the managed database cluster on DO Apps

In our Django project that we are testing via DO Apps. I followed along with this tutorial

https://www.digitalocean.com/community/tutorials/how-to-deploy-django-to-app-platform#step-4-—-deploying-to-digitalocean-with-app-platform

and added this block of code.

DEVELOPMENT_MODE = os.getenv("DEVELOPMENT_MODE", "False") == "True"

if DEVELOPMENT_MODE is True:
    DATABASES = {
        "default": {
            "ENGINE": "Our local database postgres creds",
            "NAME": os.path.join(BASE_DIR, "postgres "),
        }
    }
elif len(sys.argv) > 0 and sys.argv[1] != 'collectstatic':
    if os.getenv("DATABASE_URL", None) is None:
        raise Exception("DATABASE_URL environment variable not defined")
    DATABASES = {
        "default": dj_database_url.parse(os.environ.get("DATABASE_URL")),
    }

In our environment variable at the app, we have set the Debug mode to True and DEVELOPMENT_MODE is also True.

The issue is that every time we try to run the local server. We see a cookie that is creating a session and crashing the site. We have to delete that cookie to run the local env and I am suspecting that this is caused by this block of code that I mentioned above. Is my assumption is correct and how can I fix this?

Second, what is the best practice to add the env variable for the dev branch that can work locally and also on digital ocean apps? I am thinking that on my local machine

Debug == TRUE DEVELOPMENT_MODE == True

and the env variable at the DO app as.

Debug == False DEVELOPMENT_MODE == False

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I suspect your cookie issue is related to not setting a stable DJANGO_SECRET_KEY / SECRET_KEY value.

https://djangocentral.com/environment-variables-in-django/ lays out good practices for managing env vars. Be sure to add the .env file to the .gitignore to avoid committing anything sensitive to github.