0% found this document useful (0 votes)
450 views6 pages

Notes For Django Beginners by Samir Phuyal

This document provides an overview of key concepts for learning Django 2 for beginners. It covers installing Django using pip, creating a virtual environment, starting a Django project and app, model fields, migrations, superusers, Jinja2 syntax, including partials, and search queries using Q objects. The goal is to introduce the basic workflow and features of Django.

Uploaded by

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

Notes For Django Beginners by Samir Phuyal

This document provides an overview of key concepts for learning Django 2 for beginners. It covers installing Django using pip, creating a virtual environment, starting a Django project and app, model fields, migrations, superusers, Jinja2 syntax, including partials, and search queries using Q objects. The goal is to introduce the basic workflow and features of Django.

Uploaded by

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

 

Notes 
Learn Django 2 for beginners 
 

What will we cover? 


1. Using pip 
2. Creating a Virtual Environment 
3. Activating Virtual Environment 
4. Starting Django project 
5. Creating an app 
6. Different Model Fields 
7. Making migrations 
8. Creating a superuser 
9. Jinja 2 Syntax 
10. Including partials 
11. Doing Search Queries 

Note:​ ​I will be adding more notes always! 

Using pip 
To install packages 

pip install django 


 

To uninstall packages 

pip uninstall django 


Note:​ ​You can find more packages at ​https://pypi.org/ 

 
 

Creating Virtual Environment 


On Unix or Mac OS 

python3 -m venv name-env 

 
On Windows 

python -m venv name-env 

Activating Virtual Environment 


On Windows 

source name-env\Scripts\activate 


 

On Unix or Mac OS 

source name-env/bin/activate 
 

Starting Django Project 

django-admin startproject <name> 


 

Creating an app 

python manage.py startapp <name> 


 

Different ModelFields 

CharField(max_length=None) 

DateTimeField(auto_now=False,auto_now_add=False) 

EmailField(max_length=None) 

FileField(upload_to=None,max_length=100) 

ImageField(upload_to=None,max_length=100) 

IntegerField() 

SlugField(max_length=50) 


 

TextField(max_length=1000) 

URLField(max_length=100) 

ForeignKey(ModelName,on_delete=models.CASCADE) 
 

Making Migrations 

python manage.py makemigrations 

python manage.py migrate 


 

Creating a SuperUser 

python manage.py createsuperuser 


 

Jinja 2 Syntax 

- Accessing Value {{ name }} 


- Setting url navigation {% url ‘ ’ %} 
- Loading static {% load static %} 


 

- Using Conditional: 

{% if expression %} 

… 

{% elif expression %} 

… 

{% else %} 

…  

{% endif %} 

- Looping using for loop 

{% for item in items %} 

…  

{% endfor %} 
 
 
 


 

Including partials 

{% include ‘path_to_partial’ %} 


 

Doing Search Queries 

from django.db.models import Q

Q(ModelField__startswith=’term’) 

Q(ModelField__icontains=’term’) 

Q(ModelField__iexact=’term’) 

Q(ModelField__lt=20) # less than 

Q(ModelField__lte=20) # less than or equal to 

Q(ModelField__gt=20) # greater than 

Q(ModelField__gte=20) # greater than or equal to 


 

Note:​ ​More notes will be added in the future! 

You might also like