Create a virtual environment
Create a directory for the new project, switch the terminal to this directory, and create a virtual environment
python3 -m venv ll_env
Here the module is run venv
, creating a ll_venv
virtual environment called
Activate the virtual environment
Use the following command to activate:
source ll_env/bin/activate
To stop using, enter the commanddeactivate
Install Django
pip install Django
Create a project in Django
In the virtual environment that is still active, execute the following command:
django-admin.py startproject learning_log .
This command allows Django to create a new project called learning_log. The period at the end of the command allows the new project to use the appropriate directory structure.
(ll_env) twr@twr-911K:~/learning_log$ ls
learning_log ll_env manage.py
Running the ls
command showed that Django created a directory named learning_log, and also created a file named manage.py, which accepted the command and gave it to the relevant part of Django to run.
(ll_env) twr@twr-911K:~/learning_log$ ls learning_log
asgi.py __init__.py settings.py urls.py wsgi.py
The learning_log directory contains 5 files, of which settings.py specifies how Django interacts with the system and how to manage projects; urls.py tells Django which web pages should be created to respond to browser requests; wsgi.py helps Django provide the files it creates
Create a database
Run the following command:
python manage.py migrate
When the command migrate
is executed for the first time, it will let Django ensure that the database matches the current state of the project. When this command is executed for the first time in a new project in use, Django will create a new database.
(ll_env) twr@twr-911K:~/learning_log$ ls
db.sqlite3 learning_log ll_env manage.py
View project
input the command:
python manage.py runserver