Module 1
Module 1
Module 1
Agenda:
Full Stack Development
Need of Full Stack Development
Django MVT framework
Django features and Applications
Installation Instructions
Project and App
Development of Django Apps
Full Stack Development with Django
Django installation:
Open a command prompt and type following
command: pip install django
Full Stack Development with Django
2. Creation of virtual environment, Django project
and App should be demonstrated
Virtual Environment Creation
1. Install the Python extension.- Open VS Code IDE and click
extensions there automatically u will be shown Python
extension (Make sure you are connected to Internet)
2. On your file system, create a project folder
3. In that folder, use the following command (as appropriate
to your computer) to create a virtual environment
named env based on your current interpreter:
# Windows
python -m venv env
Full Stack Development with Django
Http Errors
Creating project:
Type following command in the terminal
opened:
django-admin startproject first .
Full Stack Development with Django
● manage.py: The Django command-line administrative
utility for the project. You run administrative commands
for the project using python manage.py <command>
[options].
● A subfolder named first, which contains the following
files:
o __init__.py:
o wsgi.py:
o settings.py:
o urls.py:
To verify the Django project, make sure your virtual
environment is activated, then start Django's development
server using the command
python manage.py runserver.
Full Stack Development with Django
In the VS Code Terminal with your virtual environment
activated, run the administrative utility's startapp command
in your project folder (where manage.py resides):
URLs in Django
Static URLs
A static URL is a type of URL that does not
change. In technical terms, we can say that these
URL does not contain URL parameters.
Dynamic URLs
A Dynamic URL is a type of URL that can
change. These type of URLs contains special
characters like ? , = , & , + etc.
Full Stack Development with Django
Dynamic URL Path Converters
Type of path converters used in Django for
producing Dynamic URLs.
Eg: int,str, slug, path, regular expressions
Full Stack Development with Django
Identifies requests by whether the requested URL points to
a relative path that matches a pattern defined by a wildcard.
Wildcard Patterns in Django
URL Patterns: In Django, URL patterns are defined using regular expressions or simple strings
to match incoming URL requests with corresponding views. These patterns are defined in the
urls.py files of Django apps.
Wildcard Capture: Within URL patterns, you can use wildcard captures (using regular
expression syntax) to match parts of the URL dynamically. For example, if you want to capture
a numeric identifier from a URL, you might use r'^articles/(?P<id>\d+)/$', where (?P<id>\d+)
captures the numeric identifier and assigns it to a variable named id.
View Functions: These captured values can then be passed to view functions, allowing you to
process them dynamically and generate responses accordingly. In the above example, the
captured id could be passed as an argument to a view function that fetches the
corresponding article from the database.
Named URL Patterns: Django also supports named URL patterns, which allow you to
reference URLs by name rather than hardcoding them. This improves code maintainability
and flexibility. For example, you might define a URL pattern like path('articles/<int:id>/',
views.article_detail, name='article-detail'), and then refer to it in templates or code as {% url
'article-detail' article.id %}.
Wildcard Patterns in Django
Example :
urlpatterns = [
path('articles/<int:year>/', views.year_archive),
path('articles/<int:year>/<int:month>/', views.month_archive),
path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail),
]
Full Stack Development with Django
Develop a Django app that displays tables
of squares of pairs of numbers input in the
URL. Perform necessary validations.
Full Stack Development with Django
Develop a Django app that displays
number of vowels and consonants and
also list of vowels and consonants for any
input sentence specified in the URL.
Full Stack Development with Django
Full Stack Development with Django
Develop a Django app that finds the mode
of a given set of numbers specified in the
URL.
Full Stack Development with Django
Design a Django app that finds whether you can
avail Vote from Home facility or not. Your age
should be passed as parameter in the URL.
Case1:URL: 127.0.0.1:8000/56
Output: You cannot avail Vote from Home as
you are 4 years younger than the threshold
age.
URL:
127.0.0.1:8000/banana,apples,grapes,orange
Output: banana,apples,grapes,orange