Django deployment

My app is working in Heroku and I'm deploying it using Dokploy. I get the error
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django/apps/config.py", line 123, in create
mod = import_module(mod_path)
^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/heroku_python/python/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django_q/apps.py", line 3, in <module>
from django_q.conf import Conf
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django_q/conf.py", line 42, in <module>
class Conf:
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django_q/conf.py", line 209, in Conf
SECRET_KEY = settings.SECRET_KEY
^^^^^^^^^^^^^^^^^^^
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django/conf/__init__.py", line 98, in __getattr__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django/apps/config.py", line 123, in create
mod = import_module(mod_path)
^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/heroku_python/python/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django_q/apps.py", line 3, in <module>
from django_q.conf import Conf
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django_q/conf.py", line 42, in <module>
class Conf:
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django_q/conf.py", line 209, in Conf
SECRET_KEY = settings.SECRET_KEY
^^^^^^^^^^^^^^^^^^^
File "/layers/heroku_python/dependencies/lib/python3.12/site-packages/django/conf/__init__.py", line 98, in __getattr__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I'm using SECRET_KEY = os.getenv('SECRET_KEY') in my settings.py and it's definitely in my environment variables with Dokploy. Anything else I'm missing?
33 Replies
Siumauricio
Siumauricio13mo ago
I can look into that I will create a django application. In the meantime can you try with nixpacks? https://nixpacks.com/docs/providers/python#start
Python | Nixpacks
App source + Nix packages + Docker = Image
James Flores
James FloresOP13mo ago
Tried with nixpacks and it didn't support Django 5+ Only 4.2.11 I ran into dependency issues I'll see if I can get it working with 4.2.11 I think the main issue is not seeing my env vars
Siumauricio
Siumauricio13mo ago
What was the issue?
James Flores
James FloresOP13mo ago
0.531 File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
0.532 File "/opt/venv/lib/python3.8/site-packages/django_q/apps.py", line 3, in <module>
0.532 from django_q.conf import Conf
0.533 File "/opt/venv/lib/python3.8/site-packages/django_q/conf.py", line 42, in <module>
0.533 class Conf:
0.534 File "/opt/venv/lib/python3.8/site-packages/django_q/conf.py", line 209, in Conf
0.534 SECRET_KEY = settings.SECRET_KEY
0.534 File "/opt/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 111, in __getattr__
0.534 raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
0.534 django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
------
0.531 File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
0.532 File "/opt/venv/lib/python3.8/site-packages/django_q/apps.py", line 3, in <module>
0.532 from django_q.conf import Conf
0.533 File "/opt/venv/lib/python3.8/site-packages/django_q/conf.py", line 42, in <module>
0.533 class Conf:
0.534 File "/opt/venv/lib/python3.8/site-packages/django_q/conf.py", line 209, in Conf
0.534 SECRET_KEY = settings.SECRET_KEY
0.534 File "/opt/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 111, in __getattr__
0.534 raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
0.534 django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
------
`
James Flores
James FloresOP13mo ago
No description
Siumauricio
Siumauricio13mo ago
@James Flores I'm back, i will create a new django application what exactly version you had in order to reproduce?
James Flores
James FloresOP13mo ago
5.0.4 (thank you)
Siumauricio
Siumauricio13mo ago
I got working in a previous version for now 4.2.11, i attach the settings, also you need to add a Procfile in order to work, here is the repo https://github.com/Dokploy/django-demo/blob/main/mysite/Procfile, tomorrow i will try with that version
No description
No description
Siumauricio
Siumauricio13mo ago
No description
James Flores
James FloresOP13mo ago
Did you have any environment variables? Can the app read any of them? That was my main issue but I will have a look at your repo soon. Was this with nixpacks?
arifkubel
arifkubel13mo ago
On my end, environment variables are also not working. i tried to deploy a Next.js application. I've tried using Dockerfile and Nixpacks, but nothing seems to work.
James Flores
James FloresOP13mo ago
Ok. Great to hear it’s not just me 😌
Siumauricio
Siumauricio13mo ago
I tried another project specifically which requires enviroment variables from a postgres database and is working the migrations were apply succesfully https://github.com/Dokploy/django-demo/tree/demo-2 is a fork from railways projects
GitHub
GitHub - Dokploy/django-demo at demo-2
Contribute to Dokploy/django-demo development by creating an account on GitHub.
No description
No description
No description
Siumauricio
Siumauricio13mo ago
the database
No description
Siumauricio
Siumauricio13mo ago
you can see the tables of migration
No description
Siumauricio
Siumauricio13mo ago
@arifkubel @James Flores you were both right, the environment variables was not passing right to the nixpacks builder, they was passing as a index something like --env 0 --env 1, now is fixed, and the version Django==5.0.4 is working now, i will make the release today
Siumauricio
Siumauricio13mo ago
No description
James Flores
James FloresOP13mo ago
Thanks so much! I'm actually just testing your repo now So with the repo, were you using Heroku buildpacks? Now I can use Nixpacks when you make the release?
Siumauricio
Siumauricio13mo ago
probably it will not work now since you need to set this env NIXPACKS_PYTHON_VERSION=3.10, and the fix is here https://github.com/Dokploy/dokploy/pull/21
GitHub
Fix/builder env wrong way by Siumauricio · Pull Request #21 · Dokpl...
Fix: Currently there was a wrong way to pass the enviroments to the builder, we was passing as a index(number) instead of the real value.
Siumauricio
Siumauricio13mo ago
Yes, when i make the release you can start using No, i was using nixpacks
James Flores
James FloresOP13mo ago
NIXPACKS_PYTHON_VERSION=3.10
NIXPACKS_START_CMD="python manage.py migrate && python manage.py collectstatic --noinput && gunicorn mysite.wsgi"
NIXPACKS_PYTHON_VERSION=3.10
NIXPACKS_START_CMD="python manage.py migrate && python manage.py collectstatic --noinput && gunicorn mysite.wsgi"
So I'll try this
Siumauricio
Siumauricio13mo ago
these are my envs
NIXPACKS_PYTHON_VERSION=3.10
PGDATABASE=django-demo
PGUSER=postgres
PGPASSWORD=vYh3VBYHUkGsyTrh
PGHOST=postgres-parse-multi-byte-alarm-jnmc5i
PGPORT=5432
NIXPACKS_PYTHON_VERSION=3.10
PGDATABASE=django-demo
PGUSER=postgres
PGPASSWORD=vYh3VBYHUkGsyTrh
PGHOST=postgres-parse-multi-byte-alarm-jnmc5i
PGPORT=5432
James Flores
James FloresOP13mo ago
Got it to build with nixpacks on the main branch with Django 4.2.11
James Flores
James FloresOP13mo ago
port 8000 right?
No description
Siumauricio
Siumauricio13mo ago
Yes Testing the changes on canary and the build and everything is working now version 5 https://canary-app-1.dokploy.com/ I will push to latest in a few minutes
James Flores
James FloresOP13mo ago
thanks. How do we upgrade our dokploy instance?
Siumauricio
Siumauricio13mo ago
Updating Procedure: Navigate to Settings > Server. Upon entry, the system will automatically begin downloading the latest server image. Please wait approximately 2 minutes for the download to complete. Once the download is finished, an "Update Server" button will appear. Click this button to proceed with the server update. if you can't see the button simply reload the page
James Flores
James FloresOP13mo ago
Done. Should it update the version number in the footer? It built! But how to do I fix "ERR_TOO_MANY_REDIRECTS" I'm using cloudflare
Siumauricio
Siumauricio13mo ago
no, the current version is the v0.0.1 so no worries
Siumauricio
Siumauricio13mo ago
Someone ask the same on github here is the answer for that https://github.com/Dokploy/dokploy/issues/18
GitHub
Exposing Port 3001 in Docker Container for Node.js Application · Is...
Hello, I want to thank you for the excellent work you've done. Currently, I'm running a Node.js application on port 3001, but this port hasn't been exposed by Docker. I'd like to kn...
James Flores
James FloresOP13mo ago
I turned off cloudflare for the record for now, so I can see that it's working. Now the page returns "Bad gateway" NVM. My issue there with deploy lol
Siumauricio
Siumauricio13mo ago
Nice
arifkubel
arifkubel13mo ago
❤️

Did you find this page helpful?