These notes are for use later when I need to write part of the deployment section for pp4
- Log in to Heroku and navigate to your dashboard.
- Click on the 'New' button in the upper right and select 'Create new app.'
- Pick a unique name for your App, select the appropriate region, and click 'Create app.'
- Click on the 'Settings' tab, scroll down to the 'Config Vars' section, and click 'Reveal Config Vars.'
- Add a key-value pair with key
DISABLE_COLLECTSTATICand value1. - Add a key-value pair with key
DATABASE_URLand value the database url provided. (If you no longer have access to this, please contact me.)
(should this be a different deployment section)
- Install a production ready web-server by entering
pip3 install gunicorn~=20.1into the terminal. - Add this to the requirements.txt file with the terminal command
pip3 freeze --local > requirements.txt. - Create a file (without any extension) named 'Procfile' in the root directory of the repository.
- Add the line
web: gunicorn my_project.wsgito this file and save it. Heroku will use this to run our web app.
(should this be a different deployment section)
- In the
settings.pyfile located in themy_projectdirectory, changeDEBUG=TruetoDEBUG=False. - While in
settings.py, append, '.herokuapp.com'to the end of theALLOWED_HOSTSlist (if there are no other hosts listed, simply add'.herokuapp.com'). (it says to remember the comma, but this is only relevant if there are other hosts, right?)
(is this even a deployment step? I guess so since we will deploy from github and need the procfile)
- Push these changes to GitHub.
- Navigate to the 'Deploy' tab of your app on Heroku and enable 'Connect to GitHub' in the 'Deployment method' section.
- Enter the name of the repository for the project in the search box and click 'Search.'
- Select the repository from the list of search results.
- Click 'Deploy Branch' to begin a manual deployment of the relevant branch.
(is this a different deployment section?)
- Scroll up and open the 'Resources' tab. there are steps about adding eco dynos and making sure there is no db installed yet. The first isn't entirely relevant to this but will be, not sure about the second. The steps are saved in logseq.
Environment variables 18. Create a file called env.py in the root directory. Add `import os
os.environ.setdefault(
"DATABASE_URL", >database_url<)where you replace>database_url<` with the database url provided.
(If you no longer have access to this, please contact me.)
static files deployment
-
install
whitenoise~=5.3.0 -
add
'whitenoise.middleware.WhiteNoiseMiddleware',to theMIDDLEWAREvariable in settings.py directly after the SecurityMiddleware from Django. -
add
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')to settings.py -
run
python3 manage.py collectstaticin the terminal -
?? check version of python3 with
python3 -v?? (in my case it was python-3.12.2) -
copy supported run time closest to yours in https://devcenter.heroku.com/articles/python-support#specifying-a-python-version (in my case it is python-3.12.3)
-
add
runtime.txtfile to root and add the run time version (in my case this is python-3.12.3) -
git add, commit, and then push these changes to github.
-
got to heroku page for the deployed app. click on settings. scroll down to config vars and remove the key value pair for DISABLE_COLLECTSTATIC
-
then redeploy??
I think the above about collect static can sort of be collapsed, like take out the earlier stuff about collect static as well.
cloudinary set up
-
download required packages for cloudinary api
pip3 install cloudinary~=1.36.0 dj3-cloudinary-storage~=0.0.6 urllib3~=1.26.15(this will likely be done by just having them install the requirements with pip). -
sign up to cloudinary
-
go to the dashboard and copy the CLOUDINARY_URL (mine is CLOUDINARY_URL=cloudinary://736759862794426:NIk-OfM7ERFV3NWf9KoSMKxTXlc@djf0ieux6).
-
go to settings and add the following to the list of installed apps.
cloudinary_storagemust be immediately afterdjango.contrib.staticfiles, and addcloudinaryas well. -
Go to settings in Heroku, Add CLOUDINARY_URL to the config vars.