make sure you have python >= 3.3 installed
python3 -m venv venv
source venv/bin/activate
If you have multiple versions of Python, now if you type > python -V: it will show the version (python3 in this case) in this virtual environment.
> pip install django
you can add a specific version as well like
pip install Django==3.1.7
try > pip freeze: will display what you have installed so far
django-admin startproject myproject
This creates a "myproject" within a new "myproject" folder; you can change the name of the outer "myproject" folder however you would like; the inner "myproject" folder is your Django "project" that contains "settings.py"
Basic folder structure
βββ /venv
βββ manage.py -> important file to "run" python
βββ /myproject -> your Django project
β βββ __init__.py
β βββ asgi.py
β βββ settings.py -> important file to set all configs in your Django project
β βββ urls.py
β βββ wsgi.py
(project root)
βββ /venv
βββ /myproject -> your Django project "conatainer" (you can rename as you wish)
β βββ manage.py -> important file to "run" python
β βββ /myproject -> your Django project
β β βββ __init__.py
β β βββ asgi.py
β β βββ settings.py -> **important file to set all configs in your Django project
β β βββ urls.py -> **important file to config URL paths in your Django project
β β βββ wsgi.py
β ...
β # -- other django apps get created in this level
β βββ /other-app01 -> "other django app 01" folder ..
β βββ /other-app02 -> "other django app 02" folder ..
...
cd myproject
python manage.py runserver
β¨ If success, you will be able to load http://127.0.0.1:8000/ or http://localhost:8000/!!!
deactivate
python manage.py createsuperuser
Now you can login to the admin site @ http://127.0.0.1:8000/admin or http://localhost:8000/admin
Just run these 2 commands:
source venv/bin/activate
in the project root to activate the virtual env
python manage.py runserver
cd into the django project container -> then run
python manage.py runserver
Set your Postgre DB instead of SqLite:
# @your-django-proj/settings.py
DATABASES = {
'default': {
"ENGINE": "django.db.backends.postgresql",
"NAME": "<your-postgresql-db-name>",
"USER": "<your-postgresql-username>",
"PASSWORD": "<your-postgresql-password>",
}
}
pip freeze > requirements.txt
all installed Django pkgs will be listed into a new text file called "requirements.txt"
pip install -r requirements.txt
option: -r, --requirement : Install from the given requirements file. This option can be used multiple times.
or pip install -r requirements.txt --no-index --find-links
HAPPY LEARNING! π
DJANGO Guide https://docs.djangoproject.com/en/3.1/
Django at a glance https://docs.djangoproject.com/en/3.1/intro/overview/