Hi Guys,
Please share detail level steps to push the django code from local to Heroku server?
As I am new to Django , I have developed some small app where I want to deploy into Heroku server.
Also in the steps, please provide details about what has to install in my local ,etc..
Please find below the details,
Create the App in Heroku using below URL,
https://dashboard.heroku.com/apps
Step 1:
heroku login
Step 2:
Navigate to the Django Project folder where manage.py resides
Step 3:
git init
Step 4:
heroku git:remote -a <app_name>
Step 5:
Create Procfile in PROJECT_HOME dir
Step 6:
pip install gunicorn
Step 7:
pip install django-heroku
Step 8:
import django_heroku
Add the following import
statement to the top of settings.py
:
Step 9:
Then add the following to the bottom of settings.py
:
django_heroku.settings(locals())
Step 10:
Django does not support serving static files in production. However, the fantastic WhiteNoise project can integrate into your Django application, and was designed with exactly this purpose in mind.
pip install whitenoise
Step 11:
Next, install WhiteNoise into your Django application. This is done in settings.py
’s middleware section (at the top):
MIDDLEWARE_CLASSES = (
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
'whitenoise.middleware.WhiteNoiseMiddleware',
)
Step 12:
Finally, if you’d like gzip functionality enabled, also add the following setting to settings.py
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Step 13:
If collectstatic failed during a build, a traceback was provided that will be helpful in diagnosing the problem. If you need additional information about the environment collectstatic was run in, use the DEBUG_COLLECTSTATIC
configuration.
heroku config:set DEBUG_COLLECTSTATIC=1
Step 14:
Sometimes, you may not want Heroku to run collectstatic on your behalf. You can disable the collectstatic build step with the DISABLE_COLLECTSTATIC
configuration:
heroku config:set DISABLE_COLLECTSTATIC=1
Step 15:
git add .
Step 16:
git commit -am "Initial commit"
Step 17:
git push heroku master
Check this and let me know if you need more info.
Check out this link
https://www.teckiy.com/blog/step-by-step-guide-to-deploy-django-web-app-on-heroku-1782542860/
Hope this helps!
Thank you. Your blog really helped me to deploy it. But after deploy I am getting "Application 500 error"
- p789ahm 4 years, 6 months agoHi, run the command " heroku logs --tail --app your_app_name " and check the logs of your application(mostly this will help you in finding the error and resolving it accordingly)
- Jaanvi
Follow the steps... This may Help you....
In your terminal, use the "heroku login" command to log in to the Heroku CLI.
"git clone https://github.com/heroku/python-getting-started.git" to copy a basic django skeleton project to your local.
rename python-getting-started to whatever.
cd into this directory.
run the following command: "pip install -r requirements.txt" Note: Postgres must be properly installed in order for this step to work properly.
run the following command: "python manage.py collectstatic"
Install redis on Mac: "brew install redis"
Start redis server: "redis-server&" (The & at the end is to run it as a background process)
Test if Redis server is running: "redis-cli ping". If it replies “PONG”, then it’s good to go!
Install celery: "pip install celery"
Make a tasks.py file in your application directory with the following code:
"cd .." back into root directory.
Run celery: "celery worker -A=location of tasks&"
run: "python manage.py shell" in your root directory.
As your tasks celery server has been started, you can now use it to run your task just by importing tasks.py script, e.g from Python interpreter interactive mode:
This should return an Async message.
** Note: If you run "celery worker -A=location of tasks.py&" and it gives the message:
Try restarting the redis server with the command: "brew services restart redis"
Also , for more You can refer to the below link.
https://www.codementor.io/@jamesezechukwu/how-to-deploy-django-app-on-heroku-dtsee04d4