Run these commands on the terminal.
Create a virtual environment first with the below-given command.
note:- the dot at the end means the current directory.
virtualenv -p python3 .
Now activate the environment.
source bin/activate
To deactivate –
source bin/dactivate
Use these commands to check what all stuff has been installed in your virtual environment.
pip freeze
To install any package –
pip install django==3.0.5
To create the project –
django-admin.py startproject my_project .
To Run the server
python3 manage.py runserver
Next is to create an app, the command is –
python3 manage.py startapp my_app
To make a migration file
python manage.py makemigrations
To migrate to the database
python manage.py migrate
MODELS –
- Models in python are a class which represent a table in a database
- Each type of data we have (e.g Articles, Users) is represented by its own model
- Each model maps to a single table in a database
ORM commands –
from Articles2.models import Articles
Articles.save()
Articles.objects.all()
Articles.title
Articles.objects.all()[0].title
Admin page –
Reset the admin portal password.
First, create a new user
python3 manage.py createsuperuser