Django Heroku Profile - python

I am having trouble running my django app on Heroku. Following is my file structures:
---django_blog
---media_cdn
---static_cdn
---Procfile
---requirements.txt
---runtime.txt
---src
---blog
---...
---settings.py
---manage.py
---...
So 'src' is actually is my project root, and 'blog' is my app. I tried made the procfile to be
web: blog.wsgi --log-file -
and
web: src.blog.wsgi --log-file -
But none of them works. When I checked the heroku logs file, I found this error:
ImportError: No module named 'blog'

From Heroku documentation:
First, and most importantly, Heroku web applications require a
Procfile.
This file (named Procfile) is used to explicitly declare your
application’s process types and entry points. It is located in the
root of your repository.
You need to be more specific about how you declare your process types, if you are using gunicorn for this you will declare --chdir because you want to run it from different folder:
web: gunicorn --chdir src myproject.wsgi --log-file -
On the other hand I'm not using gunicorn rather I declare it like this:
web: python myproject/manage.py runserver 0.0.0.0:$PORT --noreload
FYI - Switch to gunicorn in production!

Related

environment variable issue with procfile heroku

I am doing a Heroku tutorial and web: python manage.py runserver 0.0.0.0:$PORT creates the error when I run heroku local or heroku local -p 5000 (or one of several more variants). However, web: python manage.py runserver 0.0.0.0:5000 works fine. I suspect I am making a simple error with how to pass an environment variable into the Procfile.
The error message is: CommandError: "0.0.0.0:$PORT" is not a valid port number or address:port pair.
The problem was a difference between Windows and Linux. The solution is below for others' benefit.
on linux, $PORT references the variable called PORT
on windows, we instead need %PORT%
Hence, web: python manage.py runserver 0.0.0.0:%PORT% works for Procfile.windows. To run the Windows specific Procfile, run heroku local web -f Procfile.windows as the normal Procfile file should be left with web: python manage.py runserver 0.0.0.0:$PORT so it works when deployed (as heroku machines use linux)

Django application structure,

I'm trying to deploy my Django project to Google AppEngine, however I can't figure out how to properly set up application entrypoint.
This is my whole project structure:
app.yaml
main.py
service:
manage.py
service-project:
wsgi.py
settings.py
...
service-app-1:
...
service-app-2:
...
How can I make it work? I tried to move main.py to service directory and use entrypoint: gunicorn --chdir /service main:application in app.yaml but it results in Error: can't chdir to '/service', I guess AppEngine doesn't allow to change directory.
You need to change entrypoint: gunicorn --chdir /service main:application to entrypoint: gunicorn --chdir ./service main:application in your app.yaml.
The reason you are seeing Error: can't chdir to '/service' is because gunicorn is trying to change directory to the service folder in your root directory.
Adding dot in front of the slash will make it change directory to the service folder in your project, this is because the dot refers to the current directory where your app.yaml is.

Deploying a python flask web application on Heroku with Windows

I am trying to deploy a flask app I made to Heroku with success.
The app is generated but I get errors when I push the code to the Heroku repository.
My flask app is inside a module called server.py and the variable is named app.
At first I tried using gunicorn and writing
web: gunicorn server:app
and deplying but no web dynos were up and I get an error stating it is the Procfile file.
Red about it about and saw that Gunicorn is not really working on windows so I tried installing Waitress and deploying without success. this time my profcile was written as all of these (tried several times):
web: waitress-serve --listen=*:8000 server.wsgi:application
web: waitress-serve --listen=*:8000 app.wsgi:application
And so on.
to add a web dyno I should scale it because heroku ps: showes that there is no dynos.
When I try to run heroku ps:scale web=1 I get:
Scaling dynos... !
â–¸ Couldn't find that process type.
What am i doing wrong?
I was having the same problem. Particularly, waitress works locally in Windows (inside a Procfile.windows file web: waitress-serve index:server, then with heroku CLI heroku local -f Procfile.windows), but failed after Heroku deployment. Workaround for me was to locally test with waitress (like explained), but deploy with gunicorn (web: gunicorn index:server inside Procfile). Let me know if this works for you.

Newrelic error in Django : Configuration has already been done

I am getting this error when i am trying to run
python manage.py runserver for my Django Project,
newrelic.api.exceptions.ConfigurationError: Configuration has already been done against differing configuration file or environment. Prior configuration file used was "/home/project/newrelic.ini" and environment "staging".'
What does it mean ?? How to approach it?
Have you just setup New Relic?
I believe this is a problem with your procfile. Which you most likely just have edited.
Your procfile should look something like this, depending on your wsgi.
web: newrelic-admin run-program gunicorn hello.wsgi --log-file -

Configuring gunicorn for Django on Heroku

I'm trying to setup a test Django project on Heroku. Following the advice here and in the Heroku Getting Started I'm trying to use gunicorn instead of the Django dev server.
This was my first attempt at the Procfile:
web: gunicorn_django --workers=4 --bind=0.0.0.0:$PORT my_project/settings.py
worker: python my_project/manage.py celeryd -E -B --loglevel=INFO
This gave me this error:
ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named py
I decided to take a different track and followed the advice here. Now my Procfile looked like this:
web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload my_project.settings
(I also updated my requirements file to include gevent.) It gave me the same error:
ImportError: Could not import settings
Finally, I just set it to settings:
web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload settings
But now I get this error:
Error: django project not found
The way my Django project is set up is that the settings.py file is in the parent directory of the repo -- I don't have the Django project under another directory. It's at the same level as the virtualenv and git files. Would that be a problem? I'm sure I'm doing something simple wrong -- any help would be much appreciated.
If I follow the instructions from Heroku here and change the Procfile to this:
web: gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT
Nothing happens -- no errors in the logs, but no proceses run and the app just appears dead in the water.
I have just run into this same issue. In the procfile you copied from the Heroku guide, change hellodjango.wsgi to yourproject.wsgi
Looks like we all fall victim to blindly copy-pasting now and then, but in your (and my) defense, it looks like there's no *.wsgi file that's actually being opened, it's just how you signal to gunicorn that you want it to run your django project.
I had the same exact issue that you are having. The way I was able to finally get it working was to use the django app gunicorn.
I added gunicorn to the django settings.py
'gunicorn',
I then used this as my web entry in my Procfile.
web: python manage.py run_gunicorn -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload
You may have to alter you .manage.py if you use a different directory structure then I did. My app was in /app, and my python path was also /app.
I had this issue and landed up having to point directly to the python path and then set the settings reference.
In the end my Procfile looks like this:
web: gunicorn_django --pythonpath=/app/project --settings=settings
I had to run heroku run which showed the env variables and that's where I was able to find the /app which I prepended to my project name.
Do you have a requirements.txt in the root folder (containing the word django), as well as a settings.py? Those appear to the be the requirements for Django app detection, as documented here.

Categories