how to deploy to heroku djangorest framework app

To deploy a Django app with Django REST Framework to Heroku, you can follow these steps:

  1. Create a Heroku Account: If you don't have one already, sign up for a free Heroku account at heroku.com.

  2. Install the Heroku CLI: Download and install the Heroku CLI, which provides a command-line interface for deploying apps to Heroku.

  3. Set up a Git repository: Initialize a Git repository in your Django project folder by running the command git init.

  4. Create a Heroku app: In your terminal, navigate to your project folder and run heroku create to create a new Heroku app. This will also add a Git remote to your repository.

  5. Configure the app: Set the ALLOWED_HOSTS setting in your Django settings file to include your Heroku app's domain. You can find this by running heroku apps:info in your terminal.

  6. Install required dependencies: Add gunicorn and psycopg2 (if you're using PostgreSQL) to your requirements.txt file. These are required for running your app on Heroku.

  7. Create a Procfile: In the root of your project directory, create a file called Procfile (without any file extension) and add the following line: web: gunicorn your_project_name.wsgi.

  8. Commit and push your code: Commit your changes to Git by running git add . followed by git commit -m "Initial commit". Then, push your code to the Heroku remote repository using git push heroku master.

  9. Set up database: If you're using a database, configure it on Heroku. For example, if you're using PostgreSQL, run heroku addons:create heroku-postgresql:hobby-dev to add a PostgreSQL database to your app.

  10. Migrate your database: Run heroku run python manage.py migrate to apply any pending database migrations on Heroku.

  11. Scale your app: By default, Heroku assigns only one web dyno to your app. To scale it, run heroku ps:scale web=1.

  12. Visit your app: Finally, run heroku open to open your app in a browser and verify that it's working.

That's it! Your Django app with Django REST Framework is now deployed on Heroku.