A tutorial of a fully developed back end from inception through deployment using Django and Python.
Navigation is set to the side with the clickable links moving you down the page through the tutorial
code example
(typical presentation of python code in README.md)
def item_delete(request, pk):
item = Item.objects.get(pk=pk)
parent_id = item.todo.pk
item.delete()
return redirect('todo_detail', pk = parent_id)
(I have included a copy this checklist in the issues tab of this repo making the checkboxes clickable for easy tracking of progress)
- Make a directory for the project
- Install python3 and virtual environment with
brew install python pipenv
- Run
pipenv install django
andpipenv install psycopg2-binary
to create django application with PostgreSQL - Run
pipenv run django-admin startproject <project name> .
to initialize the project - Start the virtual environment with
pipenv shell
- Create the application inside the project with
django-admin startapp <application name>
- Open PostgreSQL with
psql -d postgres
- Create the database, user, password, and privileges for the application
- Update
settings.py
to reflect the current database -
python3 manage.py runserver
to check everything has been installed correctly!
- Make Models in
models.py
with Primary Key and Foreign Key Relationships - Run
python3 manage.py makemigrations
to connect the Models to the database - Run
python3 manage.py migrate
to copy the data over - Create a superuser for the admin panel
python3 manage.py createsuperuser
- Register the Models in
admin.py
- Visit localhost to populate local database
- Import Models in
views.py
- Create python methods for list, detail, create, update, and delete
- Add
urls.py
to the Application directory - Create urlpatterns paths for all python methods
- Add
forms.py
to the Application directory and create ModelForms - Add
templates
to the Application directory - Create html pages for base along with list, detail, and form for each Model
- Add the includes path to
urls.py
in the Project directory - Update all html pages to display data from the database
- Connect Stylesheet and add CSS to Django views
- Install dependencies
pipenv install django-cors-headers gunicorn whitenoise dj-database-url django-heroku python-decouple
- Create
requirements.txt
from virtual environment by runningpip freeze > requirements.txt
- Create
Procfile
in the Root directory and addweb: gunicorn <project name>.wsgi
to it - Add cors and adjust the secret_key in
settings.py
- Run
heroku create honeydo-app
to create the Heroku copy of your application - Run
heroku addons:create heroku-postgresql:hobby-dev
to connect the database - Upload to Heroku
git push heroku master
- Migrate the database to Heroku
heroku run python manage.py migrate
- Open the application!
heroku open
All tutorials are built with HTML and CSS
Please submit bugs and problems via the issues tab in this repo and feel free to browse other tutorials and content on my website.