Introduction to Django. Start and configure new project
Django - powerful framework, writed in Python for building web-based applications. Django use model-view-control (MVC) software designing pattern. With Django you can develop applications from simple sites to complex high-loaded systems. The most important idea of Django - don’t repeat yourself (DRY) philosophy. Django have a lot of out-of-box classes and functions for building beautiful applications.
This tutorial help you for start working with Django framework: create virtual environment, start new project, run migrations, create superuser and run built-in webserver.
Create virtual environment (VENV). Virtual environment needs for keeping separated dependencied of each project, installed with Python Package Index (PIP). This command creates env named virtual environment (works in Linux and Windows systems):
python -m venv env
Activate virtual environment in Linux:
source env/bin/activate
Activate virtual environment in Windows:
.\env\Scripts\activate.bat
Install Django package with PIP:
pip install django
Start new project. The basic command is:
django-admin startproject yourprojectnameYou must see yourprojectname directory, which contain manage.py script and yourprojectname subdirectory. Inside the nested yourprojectname you should see __init__.py, asgi.py, settings.py, urls.py, wsgi.py files.
Running migrations need for synchronization database with Models:
python manage.py migrate
To gain access in built-in Admin panel we need to create superuser. Specify username, email address (not required) and password twice:
python manage.py createsuperuser
Django have embedded webserver for development and debugging. If hostname and port not sepcified, it listen 127.0.0.1 and 8000 port:
python manage.py runserver
Open in browser http://127.0.0.1:8000/ url and see Django's welcome page:
Open Admin panel by http://127.0.0.1:8000/admin/ url and auth with early created credentials. Admin panel: