Initialize a virtual environnement using venv:
yourlaptop@laptop:~/some_path/ :$ python3 -m venv env
Activate virtual environnement :
yourlaptop@laptop:~/some_path/ :$ source env/bin/activate
Deactivate virtual environnement:
(env) yourlaptop@laptop:~/some_path/ :$ Deactivate
Install Django on the virtual environnement:
(env) yourlaptop@laptop:~/some_path/ :$ pip install django
This will automatically install the latest version of django if you want to specify the version do it like this :
pip install django==2.2.2
Start The Server
(env) yourlaptop@laptop:~/some_path/ :$ python3 manage.py runserver
For me i am using python3 you can use python if you want
Uninstall a library :
pip uninstall django
Just Use
pip uninstall "Library Name"
Check & Save All Installed Libraries In Your Environnement :
// This will log all libraries installed
(env) yourlaptop@laptop:~/some_path/ :$ pip freeze
// This will save them in an external text file named requirements
(env) yourlaptop@laptop:~/some_path/ :$ pip freeze > requirements.txt
Install Libraries That you Saved :
pip install -r requirements.txt
Create a django project :
(env) yourlaptop@laptop:~/some_path/ :$ django-admin startproject mysite
Create a django app :
(env) yourlaptop@laptop:~/some_path/ :$ python3 manage.py startapp myapp
Make Migtations :
(env) yourlaptop@laptop:~/some_path/ :$ python3 manage.py makemigrations
Migration :
(env) yourlaptop@laptop:~/some_path/ :$ python3 manage.py migrate
Create a Super user :
(env) yourlaptop@laptop:~/some_path/ :$ python3 manage.py createsuperuser
Make The Secret Key In The Environnement :
First install the library:
pip install django-environ
Create a .env file your env file must be in .gitignore
Write in .env file the your secret key like this
SECRET_KEY=yoursecretkey
At The Top of
settings.py
insert The following Code
import environ
env = environ.Env()
environ.Env.read_env()
Now You can access your Env Variable write it like this :
SECRET_KEY = env("SECRET_KEY")
Notes :
Spaces are important in Jinja
Top comments (0)