Start Django in a virtual environment with Pipenv.
Placing Django on a virtual environment using Pipenv will always result in the same results for builds with Docker and team development, making development smoother. We consider it a best practice for development with multiple people and Docker.
This article is part of the Build a Django app on Docker and deploy it to AWS Fargate project.
Install pipenv using pip.
$ pip install pipenv
After installing pipenv, create a hello directory on your desktop and change to the hello directory.
$ cd ~/Desktop
$ mkdir hello && cd hello
Install Django on your virtual environment using the Pipenv command.
$ pipenv install django==2.2.3
After execution, Pipfile and Pipfile.lock files will be created. The Pipfile records the name and version of the library to install. Pipfile.lock records information about the libraries that were actually installed.
$ ls
Pipfile Pipfile.lock
Enter the virtual environment and run the startproject command to create a new Django project. Don't forget the period.
$ pipenv shell
(hello)$ django-admin startproject hello_project .
Perform migration to initialize the database and start the Django development server.
(hello)$ python manage.py migrate
(hello)$ python manage.py runserver
If you access http://127.0.0.1:8000/ with your browser, you'll see the Django welcome page. This confirms that Django is running in the virtual environment.
Recommended Posts