By kashifShrimp
In our Django project that we are testing via DO Apps. I followed along with this tutorial
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
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!
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.
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.