samedi 9 août 2014

Django et gunicorn : spécifier le chemin d'accès au fichier django.wsgi dans des dossiers spécifiques environnement pour Heroku - Stack Overflow


I have my project based on the django startproject: https://github.com/lincolnloop/django-startproject/


Here is my procfile:


web: gunicorn <myproject>.wsgi:application

Right now I have my set up like this:


[myproject]
---[conf]
------[local]
---------settings.py
------[qa]
---------settings.py

---[server_configs]
------[local]
---------django.wsgi
------[qa]
---------django.wsgi


My django.wsgi looks like this:


import os
import sys
import django.core.handlers.wsgi

sys.path.append('/app')
sys.path.append('/app/myproject')

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.conf.qa.settings'
application = django.core.handlers.wsgi.WSGIHandler()

I want to use the qa/django.wsgi for Heroku, but I am getting an error saying:


ImportError: No module named [myproject].wsgi


I have already gone through and tried solutions in this post: Configuring gunicorn for Django on Heroku but with no luck on my end.


Right now my PYTHONPATH is /app and have already tried Gunicorn+Django+Heroku. Python Path Issue with no luck either.




I had a similar problem once. Basically, you're running gunicorn from your root directory, but your wsgi is in [my_project]/[server_configs]/[qa]/.


There are two ways to go about it. If each of those directories has an init.py file, you can call it like a normal python module. Use:


web: gunicorn [myproject].[server_configs].[qa].django.wsgi:application

If they don't have init.py files (I didn't), you'll need your Procfile to switch into the proper directory. Try:


web: sh -c 'cd [server_configs]/[qa] && gunicorn django.wsgi:application'

Basically this is running a command in your shell to (1) change directories and (2) run gunicorn.




Heroku allows you to use environment variables in your Procfile. If you define an environment variable on Heroku, like so: heroku config:set WSGI_PATH=path/to/my/file/wsgi.py, then in your Procfile do: gunicorn $WSGI_PATH:application you should be good to go!



I have my project based on the django startproject: https://github.com/lincolnloop/django-startproject/


Here is my procfile:


web: gunicorn <myproject>.wsgi:application

Right now I have my set up like this:


[myproject]
---[conf]
------[local]
---------settings.py
------[qa]
---------settings.py

---[server_configs]
------[local]
---------django.wsgi
------[qa]
---------django.wsgi


My django.wsgi looks like this:


import os
import sys
import django.core.handlers.wsgi

sys.path.append('/app')
sys.path.append('/app/myproject')

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.conf.qa.settings'
application = django.core.handlers.wsgi.WSGIHandler()

I want to use the qa/django.wsgi for Heroku, but I am getting an error saying:


ImportError: No module named [myproject].wsgi


I have already gone through and tried solutions in this post: Configuring gunicorn for Django on Heroku but with no luck on my end.


Right now my PYTHONPATH is /app and have already tried Gunicorn+Django+Heroku. Python Path Issue with no luck either.



I had a similar problem once. Basically, you're running gunicorn from your root directory, but your wsgi is in [my_project]/[server_configs]/[qa]/.


There are two ways to go about it. If each of those directories has an init.py file, you can call it like a normal python module. Use:


web: gunicorn [myproject].[server_configs].[qa].django.wsgi:application

If they don't have init.py files (I didn't), you'll need your Procfile to switch into the proper directory. Try:


web: sh -c 'cd [server_configs]/[qa] && gunicorn django.wsgi:application'

Basically this is running a command in your shell to (1) change directories and (2) run gunicorn.



Heroku allows you to use environment variables in your Procfile. If you define an environment variable on Heroku, like so: heroku config:set WSGI_PATH=path/to/my/file/wsgi.py, then in your Procfile do: gunicorn $WSGI_PATH:application you should be good to go!


0 commentaires:

Enregistrer un commentaire