We start setting up a Coffee Shop project in Django
How to create and activate the virtual environment?
To start, we position ourselves in the desired folder in our editor. We create the virtual environment with:
python -m venv <path_save_path>/Coffee_Shop
Activate the environment with:
source Coffee_Shop/bin/activate
We verify its activation and proceed to install Django:
pip install django
How to start a Django project?
We create the project using the command:
django-admin startproject Coffee_Shop
We list the folders to confirm the creation of the project. Open the project in Visual Studio Code:
code -r Coffee_Shop
Now we have the manage.py
file and the configurations ready in our editor.
Which extensions to install in Visual Studio Code?
We take advantage of Visual Studio Code alerts to install essential extensions such as:
- Python
- PyLance
- Python Debugger
- Black (code formatting)
- Django (to visualize templates)
How to set up version control with Git?
We initialize a Git repository:
git init
We add and commit the initial files created by Django:
git add . git commit -m "Initial setup".
How to create and use a .gitignore file?
To avoid uploading unnecessary files to the repository, we generate a .gitignore
file with gitignore.io specifying "Django" as the criteria. We paste the generated content into a new .gitignore
file and commit it:
git add .gitignore git commit -m "Add .gitignore".
How to manage the project dependencies?
We create two files to manage dependencies:
- requirements.txt: for production dependencies.
- requirements-dev.txt: for development dependencies such as
iPython
.
We add the dependencies installed in our current environment:
pip freeze > requirements.txt
We comment both files:
git add requirements.txt requirements-dev.txt git commit -m "Add requirements files".
How to continue with the project setup?
With the environment ready, it is important to create an HTML base file to serve as a template. I challenge you to create base.html
with a menu and a footer to use in the Django course.
Want to see more contributions, questions and answers from the community?