0% found this document useful (0 votes)
6 views42 pages

Django Installation

This document outlines the installation process for Django, including prerequisites such as Python and virtual environments. It details the use of pip for package management and the structure of a Django project, including its components like URLs, ORM, views, and templates. Additionally, it explains how to create a Django project and interact with it using manage.py and the development server.

Uploaded by

jeonj289
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views42 pages

Django Installation

This document outlines the installation process for Django, including prerequisites such as Python and virtual environments. It details the use of pip for package management and the structure of a Django project, including its components like URLs, ORM, views, and templates. Additionally, it explains how to create a Django project and interact with it using manage.py and the development server.

Uploaded by

jeonj289
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Django

Installation
Learning Objectives
• Install Python
• Setup virtual environments
• Install Django
Integrated Development
Environment (IDE)
Install Python
• Django requires
Python
• Options
• Your OS package
manager
• https://
www.python.org/
downloads/
Is Python Installed?
Is Python Installed?
Install Python – Multiple Versions
Installed
• There can be multiple Python versions on a single
device
• If you installed Python 3.12 and 3.13 at different times (or via
different sources), the installer often keeps them both. That
way, scripts depending on a specific version (like python3.12)
still work.

• python vs. python3 vs py


• https://stackoverflow.com/questions/50896496/what-is-the-
difference-between-py-and-python-in-the-windows-terminal
Install Python – Multiple Versions
Installed
Other External Components
• Webserver1 DO NOT USE THIS SERVER IN A PRODUCTION SETTING.
• A web application needs a web server
• Ships with a lightweight development web server. The server
runs on port 8000 on IP address 127.0.0.1 by default.
• Django can run on other web servers2
• Database Server3,4
• SQLite (default)
• PostgreSQL (recommended production)
• Also supports MariaDB, MySQL, Oracle.
pip
• pip is the package • Usually, pip is
installer for Python.1 automatically installed
• Python Package Index • py -m pip install --upgrade
pip
(PyPi)

• If not available:
• https://pip.pypa.io/en/
stable/installation/
pip
pip
pip
Pip: Package Installation Example
pip: requirements.txt
• pip freeze > requirements.txt
• Lists all packages and their versions for the current
environment.
• Saves the file to the current directory

• pip install -r requirements.txt


• install all the modules listed in the requirements.txt file.
Python Virtual Environments
• Allow Python packages to be installed in an isolated
location for a particular application rather than being
installed globally(systemwide).1
Python Virtual Environments
• Two popular tools1:
• venv
• virtualenv

• Comparison2,3
• virtualenv supports older Python versions and needs to be installed using
the pip command.
• py – m pip install virtualenv
• venv is only used with Python 3.3 or higher and is included in the Python
standard library, requiring no installation.

• For this class, they are identical!


• We will use venv
Python Virtual Environments
• Creating a virtual environment
• py –m venv <Dir>
• Activating the environment
• <dir>\Scripts\activate.bat
• Prompt prefixed with environment
• (dir) C:\
• You must activate the environment for every command
line session.
• Create a new virtual environment for every
Django/Python project.
Python Virtual Environments
Python Virtual Environments
• Updating packages in the new virtual environment
Install Django

py –m pip install
Django
Install Django (FYI)
Install Django
Install Django
• A comparison of systemwide packages vs. packages in
virtual environment
Install Django (Using
requirements.txt)
• Creating a requirements file

• Using requirements to reinstall environment


Django Project Structure
• Every Django project is made up of multiple apps. Each
contains discrete functionality

• Default apps
• admin, auth, sessions, messages, staticfiles
Django URLs
• Precise mapping between URL patterns and your views.
Django ORM
• Django's ORM (Object-Relational Mapper) means
developers can define data models in Python and query
them via a dynamic API, but you can still write SQL if
needed.
Django Views
• Views are the business logic layer that receives web
requests and returns web responses.
Django Templates
• The presentation layer that displays information to the user. It is a text
file, typically HTML, that contains variables replaced with values when
the template is evaluated and built-in tags and filters that control the
logic of the template.
Creating a Django Project
Creating a Django Project
• django-admin startproject
hello_world .
Vs.
django-admin startproject
hello_world

Creating the project in the current


directory or creating a new
directory
manage.py
• manage.py
• a command line utility to help us interact with the Dango
project.
Initial the Database (SQLite)
Django Development Server
• The development server provides live updates/status
messages as the application runs. Below shows to
status messages (http 200 & http 404)

You might also like