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 -
Related
I've developed an application in Django that I usually run in development mode:
python manage.py runserver
I do the same for my deployed instances - obviously a security issue that I now want to resolve.
From the Django docs, its not clear to me how to:
For simplicity sake, I picked wsgi (over asgi): https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ . From this page, its not clear to me how my 'runserver' command changes to run the wsgi server over the development server. Should I run the wsgi.py file? That doesn't seem to do anything.
From the page above, its not clear whether wsgi is actually a server, or more a platform/type of servers. Do I need to use uwsgi/uvicorn/etc. instead?
I'm testing on windows - uvicorn is unix only, so I tried uwsgi, but thats giving me this error message: AttributeError: module 'os' has no attribute 'uname' - I guess its Unix only as well
So I'm using the docker image I was already building for deployment - uwsgi is giving me issues again because my docker image has no compiler, so I try now with gunicorn.
that should be easy: gunicorn project.wsgi, which gives me:
ModuleNotFoundError: No module named 'project/wsgi'
my folder structure looks like:
root-folder
project
wsgi.py
settings.py
django_app_1
django_app_2
manage.py
As the manual says, the gunicorn command should work as long as you run the gunicorn command from the same location as manage.py - which is what I'm doing.
I guess I'm missing something very obvious - who knows what?
The wsgi.py file just gives you a WSGI compatible application that a WSGI HTTP server (such as Gunicorn) can run.
I guess you have to run gunicorn project.wsgi from the root folder (that one containing the project module).
Typically, the directory containing manage.py and the module in which wsgi.py resides are one and the same. But not in your case.
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!
I am following this tutorial to set up a Django application and serve it with Gunicorn on a Debian DigitalOcean server: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
I have got as far as the section starting "Now that you have gunicorn, you can test whether it can serve your Django application by running the following command". Now I'm stuck.
In other words, I can successfully run the application using python manage.py runserver, but not by using gunicorn.
I've successfully accessed my app with:
$ python manage.py runserver xx.xx.xx.xx:8000
Now from the same directory, I'm trying to run:
$ gunicorn my_django.wsgi:application --bind xx.xx.xx.xx:8001
It appears to start OK, but when I go to http://xx.xx.xx.xx:8001, I see:
Bad Request (400)
I'm not sure how to debug this: there's nothing in /var/log/gunicorn/.
I have set ALLOWED_HOSTS=['xx.xx.xx.xx'] in my settings file.
UPDATE: Being an idiot: gunicorn was looking in production settings file, not local settings file. Setting the ALLOWED_HOSTS in production settings fixed it.
I'd still really like to know how to debug problems like this though.
The answer: gunicorn was looking in production settings file, not local settings file. Setting the ALLOWED_HOSTS in production settings fixed it.
I'm running accross an error trying to push my Django project up to Heroku and I was looking to see if anyone had any insight.
! Heroku push rejected, no Cedar-supported app detected
I am guessing it is because of my folder structure in the git repo but I am not sure. My project is setup like this:
/subfolder/djangoproject/
/subfolder/requirements.txt
My Proc file content looks like this:
web: python manage.py runserver 0.0.0.0:$PORT --noreload --settings=djangoproject.settings.heroku
I have my project setting split and they work fine on my local. (In other words I having a setting directory with an init.py in it.)
I tried this:
/Procfile
and this:
/subfolder/Procfile
but neither worked.
Can this folder structure be the culprit? I was under the impression that the requirements.txt was how Heroku found where the project folder was.
Thanks
I wanted to add my solve for the first issue I had and then post the new issue I am having.
The solve I first did was to move the Procfile and requirements.txt files to the root level of the project. The second thing I did was edit the Procfile in so the path to the manage.py script was to the proper location
web: python subfolder/djangoproject/manage.py runserver 0.0.0.0:$PORT --noreload --settings=djangoproject.settings.heroku
I've hit a new error now when trying to run a syncdb. It seems to go through the process but nothing takes. In other words, if I run syncdb once and then run it a second time, it wants to set everything up all over again. Any thoughts on what I may have configures wrong to make the DB not save it's data? Should I use the setting for the DB from the dashboard or keep this line in the Django config:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
Thanks
You need requirements.txt or setup.py in the root of the repo.
See https://github.com/heroku/heroku-buildpack-python/blob/master/bin/detect
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.