Error during deploying django app in Heroku - django

I am trying to deploy a Django application to Heroku. When I followed the documentation and tried the command git push heroku master, I am getting an error: failed to push some refs to 'https://git.heroku.com/sleepy-eyrie-25993.git'. I searched online and tried to use git pull. But it didn't work. I also tried using git push -f heroku master, but still getting the same error. Is there any other way to do it? I followed this doc
https://devcenter.heroku.com/articles/python-support.
Tried using the heroku dashboard, but it is giving the same error
Building on the Heroku-18 stack ! No default language could be detected for this app. HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically. See https://devcenter.heroku.com/articles/buildpacks ! Push failed

You can also deploy from your application dashboard on Heroku

Heroku deployment requires requirements.txt in the root of the repository.
Also, to run a Django app - it requires file Procfile
Sample content:
web: gunicorn your_app_name.wsgi:application --log-file -
You can also try to specify buildpack manually by executing:
heroku buildpacks:set heroku/python
Then if there are additional errors starting - they will be more specific
Also settings.py of your Django application should contain the following:
import django_heroku
django_heroku.settings(locals())
For more details, please refer Here

Related

AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type' QGIS Docker container to Heroku

There is a really old thread on stackoverflow here Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a syncdb
but the difference that I have with their issue is that my containers have the POSTGIS and POSTGRES installed in. Specifically I used QGIS and the image is like so
db:
image: kartoza/postgis:13.0
volumes:
- postgis-data:/var/lib/postgresql
So locally I have two docker images - one is web and the other is the kartoza/postgis
I also have this as well in the settings.py file
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
which should support the GIS data. I see all my packages gis, geolocation packages installed with no issues. But I am getting the above error when I run heroku run python manage.py migrate
The website runs with very limited functionality as the geo variables are needed to get you past the landing page.
The steps I have taken to deploy is
heroku create appname
heroku stack:set container -a appname
heroku addons:create heroku-postgresql:hobby-dev -a appname
heroku git:remote -a appname
git push heroku main
EDIT The db url on heroku is postgres://foobar:3242q34rq2rq32rf3q2rfq2q2r3vq23rvq23vr#er3-13-234-91-69.compute-
I have also ran the below command and it shows that the db now takes GIS, but I still get the error
$ heroku pg:psql
create extension postgis;
try replacing db with localhost
heroku config:add DATABASE_URL=postgis://foo:bar#localhost:5432/gis
Ok so after 14 or so hours of reading. The issue here is that
Heroku database does NOT have qgis capabilities enabled as a default - you have to use heroku pg:psql then run CREATE EXTENSION postgis;
Having QGIS installed within the docker container results it not being able to perform functions such as hero pg:push localdatabase -postgresqlremoteherokudb and heroku config:add DATABASE_URL=postgis://foo:bar#localhost:5432/gis So if anyone is following the python nearbyshops tutorial, you might end up here as well. I got fixated here thinking it's a db issue, but it was more so to do with heroku configuration settings.
If you are coming here from docker, which might mean you need to install django_heroku package to modify your settings. There are recent 2019 and 2018 guides on how to deploy Geospatial apps to heroku, but again, you don't need those. (at least for me I didn't)
GIS now is available as an extension, you no longer need to add buildpacks.
There are still some configuration issues if you are using gunicorn for staticfiles, so the website at first won't launch properly. Highly suggest that you track your heroku log errors (manual settings.py coding or heroku addons).

Why is Procfile not recognised by Heroku?

I'm trying to deploy a flask app to heroku, but I keep on getting the error:
Scaling dynos... ! ▸ Couldn't find that process type (web).
whenever I try to run heroku ps:scale web=1.
However, when I run heroku ps:scale, it tells me that I need to Upload a Procfile to add process types.
I do have a Procfile located in my root directory, and it is capitalised and doesn't have any file extensions. I have tried deleting and recreating the Procfile, but this hasn't produced any results.
How do I get Heroku to recognise my Procfile?
Here is what I've been trying to do:
ubuntu terminal
I had to create a new git repo and heroku app, and copy the code over for it to work.

Heroku collectstatic not run during deployment

I have a django app that I am successfully deplying to heroku. When I dry-run the collectstatic command locally everything works fine.
python manage.py collectstatic --dry-run --noinput
....
Pretending to copy '/Users/hari/.virtualenvs/bsc2/lib/python2.7/site-packages/django/contrib/admin/static/admin/js/admin/ordering.js'
Pretending to copy '/Users/hari/.virtualenvs/bsc2/lib/python2.7/site-packages/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js'
71 static files copied.
Despite this ..my django admin staticfiles do not get used and I get a bare-bones django admin site on heroku with Debug set to False.
If I set Debug to True I get a "rich" admin site on heroku. With Debug set to True or False "git push heroku master " command terminal output does not have anything about collecting staticfiles.
I tried the example "helloworld" application that uses gunicorn from Heroku and that did display the "collecting static" messages.I also tried inserting this code snippet into my urls.py. But that too does not help.
from django.conf import settings
if not settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
Next, I tried adding the following to my heroku config
heroku config:add DISABLE_COLLECTSTATIC=0
But that too did not show my django admin site with all the styles.
Finally I tried switching to gunicorn with my Procfile and that also did not show the admin styles. Only setting Debug=True works to show my admin styles.
I tried this with Django 1.4.2 and 1.5.1 on Heroku and neither is showing me a "normal" admin site. Is there any way out to have my admin files on heroku without going the S3 route.
command terminal output does not have anything about collecting staticfiles.
Looking at heroku-buildpack-python:bin/steps/collectstatic it seems that it tries to do a collectstatic --dry-run --noinput and pipes it's output to /dev/null before displaying the -----> Collecting static files message. This means that if there is an error there that is not present on your local box, you will never see the error on heroku : it will silently fail. (The best kind of failure ;)
have you tried running a one-off worker to test out the collectstatic command and see if it's a problem in their environment?
heroku run python manage.py collectstatic --dry-run --noinput
If this fails, it will give you an error or traceback to look into and further diagnose the issue.
Check this out Django and Static Assets. It seems to be updated recently and you can serve static files nicely using this dj-static package.
Try these three things:
Create this Heroku config variable: DJANGO_SETTINGS_MODULE with a
value of myapp.settings.prod--or as appropriate for your Heroku settings file
Use Whitenoise as described in the Heroku docs:
https://devcenter.heroku.com/articles/django-assets
Check it in and redeploy your dyno: git push heroku master
I found I was missing the first item, the DJANGO_SETTINGS_MODULE" e.g., Command line collectstatic would work but that didn't matter b/c it was an ephemeral dyno
throwing it out there, since dumb mistakes happen:
I spent much time trying to figure out why my module wasn't found on heroku when it was working fine locally, only to realize it was ignored by an entry into .slugignore

How to deploy mezzanine on heroku?

I have created a mezzanine project and its name is mezzanine-heroku-test
I create a Procfile that has the content as follow:
web: python manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3
Next, I access to the website to test and I receive the error: Internal Server Error.
So, Could you please help me deploy mezzanine on heroku step by step or some suggestion?
Thank you so much.
You should be able to see the error in the logs which you can get to using the heroku tool.
heroku logs
These are both thorough.
https://gist.github.com/joshfinnie/4046138
http://www.benhavilland.com/blog/deploying-mezzanine-on-heroku/
This is a challenging process.

How to link a folder with an existing Heroku app with mercurial

I have an existing Django app on Bitbucket and I'm able to deploy to Heroku whith hg-git. Whenever i want to run some heroku command inside my app folder i get the following errors:
$ heroku ps
! No app specified.
! Run this command from an app folder or specify which app to use with --app <app name>
$ heroku logs
! No app specified.
! Run this command from an app folder or specify which app to use with --app <app name>
etc.
Current workaround is to specify the app name: heroku ps --app <app name> but i'm looking for a way to link my repository name to the remote Heroku app name like how it's done using git.
I'm not in a position to move my app to github for now.
I'd suggest trying Hg-Git's "intree" configuration option. Set that by adding the following to your hgrc:
[git]
intree = True
With that set, the Git repository used internally by Hg-Git will be stored as a ".git" directory within the working copy, rather than nested within the ".hg" directory.
Heroku will then see this repository's config. Add a remote as suggested in the other answer (quoted below), and you should be all set.
git remote add heroku git#heroku.com:<app-name>.git
For now, the best documentation of Hg-Git configuration options that I've found is the README displayed on the project's Bitbucket page: https://bitbucket.org/durin42/hg-git
Considering heroku is looking at the .git/config file to get the app name, just do the following inside your local repository:
git init
git remote add heroku git#heroku.com:<app-name>.git
In order not to mess your repository, you'll also add the following lines to .hgignore:
#Git setup
.git/**
Now, usual heroku commands no more ask for the default app name.