29
loading...
This website collects cookies to deliver better user experience
.env
file in the project and copy and paste it into your Config Vars as below:DEBUG
to True
for now, so that we can fix any bug we encounter during deployment. We'll change it to False
later. $ git init
$ git remote add origin <your-repository-url-here>
$ git add .
$ git commit -m "Initial commit"
$ git push origin master
<your-repository-url-here>
with the URL provided by Github. See the image below for reference:$ pip install gunicorn dj-database-url whitenoise psycopg2
requirements.txt
file. We can generate it automatically using the command:$ pip freeze > requirements.txt
runtime.txt
file and add your Python version there as:python-3.9.7
.gitignore
file and add the following content:# Django #
*.log
*.pot
*.pyc
__pycache__
media
db.sqlite3
# Backup files #
*.bak
# If you are using PyCharm #
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/gradle.xml
.idea/**/libraries
*.iws /out/
# Python #
*.py[cod]
*$py.class
# Distribution / packaging
.Python build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery
celerybeat-schedule.*
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# mkdocs documentation
/site
# mypy
.mypy_cache/
# Sublime Text #
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project
# sftp configuration file
sftp-config.json
# Package control specific files Package
Control.last-run
Control.ca-list
Control.ca-bundle
Control.system-ca-bundle
GitHub.sublime-settings
# Visual Studio Code #
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
https://
and slash(/)
from the URL. For example, my URL is: https://grocery-bag-ashutosh.herokuapp.com/.
After the change, my URL looks like this: grocery-bag-ashutosh.herokuapp.com.
GroceryBag/settings.py
file and add this URL in the ALLOWED_HOSTS
list as:DEBUG = config('DEBUG', default=False, cast=bool)
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'grocery-bag-ashutosh.herokuapp.com']
MIDDLEWARE
list as:MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
# Add Whitenoise middleware here
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
django.middleware.security.SecurityMiddleware
DATABASES
dictionary as:import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles' # Add this line
STATICFILES_DIRS = [
BASE_DIR / "static",
]
web: gunicorn GroceryBag.wsgi --log-file -
web
, and the command needed to run it. The name web
is important here. It declares that this process type will be attached to the HTTP routing stack of Heroku, and receive web traffic when deployed. Notice that the Procfile file doesn't have any extension.$ git add .
$ git commit -m "Ready for deployment"
$ git push origin master