Heroku looking for the wrong wsgi file. Django - python

I'm on Django, but I'm not sure if it matters. Anyway, I get an Application Error, and when I check the logs I see the error:
ImportError: No module named redlibros.wsgi
And it is fine cause the wsgi file is not name "redlibros.wsgi", I don't even know where it gets that name. The module is named
WSGI_APPLICATION = 'letrasclub.wsgi.application' # on my settings
web: gunicorn letrasclub.wsgi --log-file - # on my procfile
and on my folders it looks like this:
LetrasClub
letrasclub
wsgi.py
templates
static
...
Any idea where to find the error?
EDIT
Ok, some extra info: I have a different repo, with a different Heroku remote. I copied that repo, changed the app, created a new Heroku remote and then pushed to the new one.
So, if I write
git remote -v
heroku https://git.heroku.com/letrasclub2.git (fetch)
heroku https://git.heroku.com/letrasclub2.git (push)
origin https://github.com/Alejoss/LetrasClub2.0.git (fetch)
origin https://github.com/Alejoss/LetrasClub2.0.git (push)
Looks fine, if I go to the old app location and write the same command I get the old remote, the one that is related to the "redlibros.wsgi" app, perfect.
Now, why when I try to push the new app to the new heroku remote, I get the error that means Heroku is looking for the Old wsgi file, I changed the wsgi name, I changed the Procfile, I changed the wsgi file declaration on the settings, what am I missing?

You look at wrong project.
You look at https://github.com/Alejoss/redlibros (I guess it's Your project), not at https://github.com/Alejoss/LetrasClub2.0

Related

What is the command for starting a WSGI server for Django?

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.

Deplying Django to Heroku - DisallowedHost Error despite Heroku URL in DJANGO_ALLOWED_HOSTS

I've been at this for hours and need help. Initially I thought it was because I had mistakenly done something small that caused it, so I deleted the app, and created everything - virtual env, heroku app, django projects/apps - fresh.
I get the same error.
I made a cookiecutter django app and deployed it to heroku. Everything goes smoothly until it's time to actually use the site.
When I run heroku open, I get the DisallowedHosts error:
DisallowedHost at /
Invalid HTTP_HOST header: 'MY-NEW-APP.herokuapp.com'. You may need to add 'MY-NEW-APP.herokuapp.com' to ALLOWED_HOSTS.
heroku config shows that DJANGO_ALLOWED_HOSTS=MY-NEW-APP.herokuapp.com. I don't overwrite it in my settings file.
I have import django_heroku and django_heroku.settings(locals()) in my settings file.
DJANGO_SETTINGS_MODULE is correctly set to that file.
What's more, I get a warning about DEBUG=True, when DEBUG=False in my settings file and in the heroku environment.
What am I missing? Are hyphens a bad thing? Should I be using herokuapp.com instead of the full URL?
Solved my own question. I just had to:
heroku config:set DJANGO_ALLOWED_HOSTS=.MY-NEW-APP.COM,MY-NEW-APP.herokuapp.com,.herokuapp.com

Deploying Flask application written in one file to Heroku

I've built a flask app and I tread to deploy it on Heroku but I got this error:
(venv) MacBook-Pro-alkhas-b-shosha:myApp joodi$ git push heroku master
error: src refspec master does not match any.
error: failed to push some refs to 'https://git.heroku.com/<app-name>.git'
I think the problem because I wrote all the application on one file.
This my app structure:
all Flask code is in flasker.py.
So when I start writing on Procfile I got confused, I didn't know what I supposed to write on it, here what I wrote
web: gunicorn myApp:app
What can I do without changing the structure?
There are a couple of issues here.
Git issue
error: src refspec master does not match any.
It looks like you haven't committed any code (Git can't find a master branch on your local system). git push operates on commits, not files.
Make sure to commit your code locally before trying to push to Heroku.
Procfile issue
Also, update your Profile to point to your flasker.py file. Assuming your Flask object is called app:
web: gunicorn flasker:app
Your error message hints to you not being on the master branch.
Try this:
git push heroku your_branch:master

How can I deploy Django Gunicorn under Apache proxy?

I've run through the documentation and am hitting the same pages over and over again. At present I've found documentation to run off an existing myapp.wsgi file, but documentation for how to make an appropriate wsgi file is a little harder to find.
If I want to make, proxied by Apache, the equivalent of, on an older version of Gunicorn etc.:
python manage.py run_gunicorn 0.0.0.0:8888
what should I be doing to supply a WSGI file for:
gunicorn project.wsgi:application
Thanks,
Why do you think you need a special wsgi file? You just use exactly the same one you would use for any other deployment.
I assume you're not asking about the content of the wsgi file (which is often pretty standard) but how to assemble a gunicorn command line that allows gunicorn to find/use the wsgi file for your project?
When deploying to a staging server, I recall having a problem getting the Python path set so that gunicorn could find the proper wsgi file for my app. Here is a trimmed version of the gunicorn command that I ended up using:
gunicorn --pythonpath /some_path/my_app/my_app my_app.wsgi:application
In plain English, starting from the right and working backward:
There is a function named application inside a the wsgi.py file
The wsgi.py file is inside a module named my_app (which in this case is a directory containing a __init__.py file)
The my_app module is located at /some_path/my_app/my_app, so this needs to be on the PYTHONPATH.
So the full path to your wsgi.py is:
/some_path/my_app/my_app/my_app/wsgi.py.
In the same directory as wsgi.py is a __init__.py file, which causes Python to recognize that directory as a module.

Django Heroku push failing

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

Categories