Table of Contents
In this project I will be showing my step by step process for building a Django Portfolio Website. Django—an open-source web framework that's designed on top of Python—can help you quickly bring your website ideas to life. I plan to illustrate my undestanding of Django for web development, by building my own website from the ground up. I will create a database, design the layout for your website, and add and update URL paths. Then I will connect my Django portfolio website to Postgres, and add static files, URLs and more.
- Setting up URLs in Django project
- Creating models in Django
- Connecting Django project to Postgres
- Adding static images
- Designing the layout for website
- Creating object views
- Updating URL paths
Here are some instructions on how to get this project up and running. First you will need some some prerequsites to manage a local virtual environment. Bellow is a list of 'Bare Minimums' you need to follow along with this project.
-
Check if
python
andpip
are installedpython --version python -m pip --version
-
If
python
is notinstalled, you can download it from the Python website. Ifpip
is not installed, run the following command or check outpython get-pip.py pip==21.0.1
-
Create a directory for the project, then download or clone project the project into the directory by simply run the following command in your terminal
mkdir project cd project git clone https://github.com/TobiAdeniyi/django-portfolio-website
-
Install and activate the virtual environment, using
pip
as sopython -m venv portfolio_website_environment source portfolio_website_environment/bin/activate python -m pip install requirements.txt pip list
Or alternatively, if you have Anaconda installed, create and activate a virtual environment, using
conda
, by running the following commandconda env create -f environment.yml conda activate portfolio_website_environment conda env list
-
TODO
Take private environment veriables from SECRET_KEY
in setings.py, and store it as a environment variable that is export
and unset
when virtual environment is activated. This is done by creating a subdirectory file
cd $CONDA_PREFIX
mkdir -p ./etc/conda/activate.d
mkdir -p ./etc/conda/deactivate.d
touch ./etc/conda/activate.d/portfolio_website_env.sh
touch ./etc/conda/deactivate.d/portfolio_website_env.sh
Then edit ./etc/conda/activate.d/portfolio_website_env.sh
and ./etc/conda/deactivate.d/portfolio_website_env.sh
respectively, as so
#!/bin/sh
export SECRET_KEY='secret-key-from-settings'
export DATABASE_URL='databse-url-from-heroku' # $(heroku config:get DATABASE_URL -a your-app)
export SECRET_PASSWORD='postgresql-password-from-postgresql'
#!/bin/sh
unset SECRET_KEY
unset DATABASE_URL
unset SECRET_PASSWORD
For more information check out Saving environment variables in the Anaconda Docs, and Connecting Heroku to Postgres in Heroku docs.
Ensure to replace SECRET_KEY
value in setings.py, for example
import os
SECRET_KEY = os.environ.get("SECRET_KEY")
- https://devcenter.heroku.com/articles/deploying-python
- https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-python
pip install gunicorn install django-heroku
echo "web: gunicorn portfolio.wsgi" >> Procfile
python -m pip freeze > requirements.txt
conda env export > environment.yml
heroku config:set SECRET_KEY=$SECRET_KEY
heroku config:set DATABASE_URL=$DATABASE_URL
heroku config:set SECRET_PASSWORD=$SECRET_PASSWORD
HEROKU CONFIG
python manage.py collectstatic
PGUSER=postgres PGPASSWORD=SECTRET_PASSWORD
heroku pg:push postgresqldb DATABASE_URL --app heroku-app-name
heroku local
git add .
git commit -m "Done :exclamation:"
git push heroku main
heroku open