/DjangoFilmsCRUD

Companion GitHub Repository for my Medium article "Build a Django CRUD App by Using Class-Based Views"

Primary LanguagePythonOtherNOASSERTION

DJANGO FILMS CRUD TUTORIAL COMPANION CODE


Author: FabrĂ­cio Barbacena



Project Description


This repository has the final version of the code I developed in my article/tutorial Build a Django CRUD App by Using Class-Based Views.

I'm putting together this present repository so that it can be used as starter code for future projects of mine. People can also find here the templates code I mentioned in my article.


How to Install the Project


  1. You need to have Python installed in your machine (3.8 or higher is recommended);

  2. Create a new folder in your machine, go inside it and clone this repository.

  3. Create a virtual environment with venv. I called mine .myenv, but you can choose another name you prefer:

python -m venv .myenv

  1. Activate the virtual environment. Below is the command for most Linux OS:

source .myenv/bin/activate

Check this Python documentation page if you have doubts about the command to start your virtual environment.

  1. Install the required Python modules (django and django-extensions):

pip install -r requirements.txt

IMPORTANT NOTE: The file settings.py is using a secret key setup with the configparser builtin Python module. So:

  1. Change the name of config_file_starter.ini to config_file.ini

  2. activate the Django shell:

python manage.py shell

  1. In the Django shell, execute the following code to generate a new secret key for your project:

from django.core.management.utils import get_random_secret_key print(get_random_secret_key())

  1. Copy the new secret key and paste it inside your config_file.ini file, replacing the PutYourSecretKeyHereWithoutQuotationMarks information. Don't use quotation marks here.

  2. Run python manage.py makemigrations and python manage.py migrate to create the necessary tables in the database;

  3. If you want your films app to be populated with a list of Pixar movies, you can also run this command:

python manage.py runscript load_pixar


How to Use the Project


  1. Start the local server with python manage.py runserver. 8000 is the default port used by Django;

  2. On your browser, access the address http://localhost:8000;

  3. Explore the Films CRUD funcionalities:

  • list all films;
  • list details from one film;
  • create a new film;
  • update and delete a film.

Licence


This project is distributed under the MIT licence (see the LICENCE document).