Author: FabrĂcio Barbacena
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.
-
You need to have Python installed in your machine (3.8 or higher is recommended);
-
Create a new folder in your machine, go inside it and clone this repository.
-
Create a virtual environment with
venv
. I called mine.myenv
, but you can choose another name you prefer:
python -m venv .myenv
- 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.
- Install the required Python modules (
django
anddjango-extensions
):
pip install -r requirements.txt
IMPORTANT NOTE: The file
settings.py
is using a secret key setup with theconfigparser
builtin Python module. So:
-
Change the name of
config_file_starter.ini
toconfig_file.ini
-
activate the Django shell:
python manage.py shell
- 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())
-
Copy the new secret key and paste it inside your
config_file.ini
file, replacing thePutYourSecretKeyHereWithoutQuotationMarks
information. Don't use quotation marks here. -
Run
python manage.py makemigrations
andpython manage.py migrate
to create the necessary tables in the database; -
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
-
Start the local server with
python manage.py runserver
. 8000 is the default port used by Django; -
On your browser, access the address http://localhost:8000;
-
Explore the Films CRUD funcionalities:
- list all films;
- list details from one film;
- create a new film;
- update and delete a film.
This project is distributed under the MIT licence (see the LICENCE document).