[PYTHON] [Django] Trouble encountered when deploying heroku Part 1

What happened?

To deploy a web app created with Django on heroku

$ git push heroku master

When I executed, the following error occurred.

"""Omission"""

remote: 
To https://git.heroku.com/hogehoge.git
 ![remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/hogehoge.git'

What is the cause?

I will write from the conclusion for those who are in a hurry.

** You did not create Procfile, runtime.txt, requirements.txt. ** **

If you're used to it, you might ask, "Is there such a thing?", But there is (crying) I made a mistake in the installation location and it was doubly clogged.

Why an error

The role of each file and how to create it are explained.

Procfile Role: ** Tell heroku which server you want to use ** Location: ** Install on project root ** (where manage.py is) Contents: Described as follows

web:gunicorn project name.wsgi --log-file -

It means that I will use gunicorn Note that the Procfile has no ** extension **!

runtime.txt Role: Inform heroku of ** Python version ** Location: ** Install on project root ** (where manage.py is) Contents: Described as follows

runtime.txt


python-3.8.5 (3.8.Describe the python version you are using in 5)

requirements.txt Role: ** Tell heroku which library you're using ** Location: ** Install on project root ** (where manage.py is) Contents: Procfile and runtime.txt must be created manually, but requirements.txt does the following in the terminal:

$cd project root directory#To run in the project root directory

$ pip freeze > requirements.txt

This is all you need. Confirm that a text file with a list of libraries is created as shown in the example below.

requirements.txt


"""
Since this is an example, the libraries you are actually using are listed.
"""

appnope==0.1.0
asgiref==3.2.10
backcall==0.2.0
beautifulsoup4==4.9.1
certifi==2020.6.20
chardet==3.0.4
click==7.1.2
coverage==5.2.1
cssselect==1.1.0
decorator==4.4.2
dj-database-url==0.5.0
Django==3.1
.
.
.

"""The following is omitted"""

important point

Of course, the above 3 files are not installed, and even if there is a mistake in the file name or contents, an error will occur, so check carefully.

reference

The site that I used as a reference First web application made with Django (extra edition) heroku deployment

Sites that may be helpful to people in the same situation [Git] What to do when git push is rejected

Recommended Posts

[Django] Trouble encountered when deploying heroku Part 1
[Django] Error encountered when deploying heroku Part 2
Solution for errors when deploying to Heroku
Deploy the Django app on Heroku [Part 1]
Django Heroku Deploy 1
Django begins part 1
Django begins part 4
Django Heroku Deploy 2
Memo of deploying Django × Postgresql on Docker to Heroku
Miscellaneous notes about deploying the django app on Heroku
heroku deployment memo (Django)
How to handle static files when deploying to production with Django
What to do if package installation fails when deploying to heroku