Setup dev environment
prerequisites¶
install pipenv¶
pipenv
is the new officially recommended packaging tool for Pythonpipenv
uses filesPipfile
andPipfile.lock
for managing the application dependencies.- it works similar to bundler, composer, npm, cargo, yarn, etc.
- install pipenv with below command
pip install --user pipenv
pipenv install - python¶
- create a directory with name "django_tutorial" with command
mkdir django_tutorial
- change directory to
cd django_tutorial
- install the latest or required python version with below command
pipenv install --python 3.10
-
above command will creates two files
Pipfile
- Pipfiles contain information for the dependencies of the projectPipfile.lock
- declares all dependencies (and sub-dependencies) of the project.venv/
- virtualenv for the project
activate pipenv¶
- activate the virtualenv with command
pipenv shell
install django package¶
- To install django just run command
pipenv install django
- Specify the django version if required
- After the command execution, it updates the
Pipfile
withdjango
package dependency.
create django project¶
- Run the command
django-admin startproject my_project
- It creates the django project and the current directory looks like below.
.
├── Pipfile
├── Pipfile.lock
└── my_project
├── manage.py
└── my_project
├── __init__.py
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
run development server¶
- Change directory with command
cd my_project
- run the development server with command
python manage.py runserver
- Open the web browser i.e chrome and access page http://127.0.0.1:8000/ to see the below screen.