Python Django Tutorial: Create a web application masterclass

Python Django Tutorial: Create a web application masterclass

  • star
  • star
  • star
  • star
  • star
(2 Reviews)

Course Description

In this lecture we are going to go in to the details of creating a dynamic web application from scratch using python and django. Django is one of the most popular python web frameworks. Well known popular websites include instagram, disqus, quora, youtube, pinterest and spotify. Full stack web development skills are highly sought after in the industry and in this course you will end front-to-back end development skills that are crucial in modern applications. I will be covering all the skills step-by-step, starting with project planning, server set up and installation of development environment, django skills, python skills, web development skills and much more. At the end of this lecture you will have your own working web application if you follow along, all the detailed steps outlined. Each concept is explained in great details from the beginning to end.

What you will learn

Learning Points, key take-aways

  • Object oriented programming (OOP) and how we use it to build complex data structures
  • Linux Virtual Private Server (VPS) set up
  • Download python, django, set up python virtual environment
  • Django basics - views, routes, templates, PostresSQL database
  • User registration process - create registration, login, logout, forgot password
  • Send emails from Django web application using python
  • Web scrapping with python, including PDF document scrapping
  • Create a python twitter bot, send automated tweets using python
  • How to deploy a Django application on Digital Ocean

Course Pre-requisites

  • Basic python knowledge

Course Skills

  • Web app developemnt
  • Linus VPS development
  • Python Programming
  • Python Django Web Framework
  • User authentication systems, Create system emails
  • Python web scrapping, PDF scrapping and parsing


Curriculum

Section-1: Introduction

In this lecture we discuss on a high level what a web application is. We discuss the difference between static and dynamic websites. Explaining client front-end, server back-end and the database components of a web app and how they talk to each other. We also go through the​ Django Project website We discuss the project planning tasks in detail: (1)Dev environment set-up, (1) project resources, (3) web content classes - Objects, (4) SEO, (5) Branding

In this lecture we purchase a droplet from Digital ocean, with ubuntu 20.04, we show you how to set up SSH keys for root login with ssh. We​ login to the droplet/vps as root from a computer terminal, create a new user and grant them sudo access. Save public key in to correct directory for new user and log in as new user in to droplet using ssh Second part of the lecture we​ Install python 3 and related items - Django Stack - Python, Database, Nginx and Gunicorn. Set up Postgres Database - create new database, user and password for our app. Continue to create python virtual environment and activate, install django and other required items. Go through Django file structure and set-up. Run through our project resources, get the FREE website template we will be using from themewagon Finally we discuss Object Oriented Programming (OOP) approach and Classes, Objects, Database rows and columns - how they integrate and how this will fit in to out app development.

SEO Key-Word Planning for Web Applications. We show you how to download SEO keyword ideas from google keyword planner. We purchase the domain we will use to host our web application. We introduce you to marketing and branding and get a logo for our web application. We show you how to download great logo templates to use for your own designs and how to edit these templates.

Section-2: Django Framework

We start by walking though Django default folders and files created when you start a django project, we go through a high level Django project architecture. Then we build our first Django app - called jobs, register our app inside the settings.py file, edit the views.py file to display - render any html file you want, create templates directory and the html file that we will display, connect Django router to display the view and html file that we just created. We then test the app we just created - to view it from the browser, display actual HTML file from template talk - one downloaded from Themeforest from Lecture 2 We start Django static folder management, move static files to django static folder - css/js/fonts/scss, register the static folder location in the settings.py file, edit the html file we downloaded for django templating, copy the updated HTML and paste in to the templates folder, home.html file inside out django app. Finally we runserver with new html to see what our homepage looks like now.

We take a look at the homepage of website we are building - job career search portal. We discuss in detail the Jobs Class - discuss all the variables that will be included in the class, navigate to the models.py file in our VPS, edit the actual models.py file in django, go through the completed code for models.py file, navigate to settings.py and specify the media route and media url - so Django knows where to save your files, register the new class/model in the admin.py file - so we can see it from the admin panel of Django, run Migrations to update out database with the new model data we just entered, log in to admin panel and enter manually data in to the database, recap on what we have done so far in this lecture We then re-write the HTML code to display data from database instead of hardocoded data and edit the views file to get data from database to serve to the front end - html.

Section-3: Django User Management

We start this lecture by fixing images from last week bu adding medial urls to your urls.py file. Create a new users application, register the new users app in the settings.py file, create a function to display the register html file, refactor the html template to django format, so django knows where to find the static folder, transfer the newly updated register html file to the VPS, inside the templates folder of the users app, go to urls py file and add the new url pattern for register route. We discuss the​ top level steps "wiring" the register form to the back-end, install the new form in the VPS, update the views inside the views.py file, update html file with the form object, show all the form fields, form errors in the django template and include custom css and html in the django forms, copy and paste updated html in to our VPS. We then test our newly created register form and viewing the new registered user in the admin panel, start with the Login page using Django built in class based Views for Login and Logout, register default login variables in the settings file, Django template extensions - base/layout html template, configure login html with form variable, install the layout template in the project directory We spend some time troubleshooting Django error "can't find template", edit the index html file to show the current logged in user their username - so they know they are logged in, create path for logout page and the logout html page.

In this lecture we will create the foundation for the Profile page - also create a new layout file, ensure that users cannot access the profile page if they are not logged in, ensure users are sent to profile page after they log in, access the user variable inside the profile.html page, start building the Resume/Profile class from scratch, going through the Resume/Profile Django model. We discuss the SlugField and why we are including it in the model, we explain in detail the SlugField. We discuss the absolute URL function inside the model class, override the Django model save function, how to get a unique string in your slug variable using uuid, how to assign a random profile image to any user who does not upload a profile image, register the models in the admin file. Finally we run python makemigrations

We correct an error on the Resume Model - overide save function(*important*), start working on the Resume form, build resume form from scratch, resume create function view, how to display the flash messages inside the HTML templates, work on create-resume html file to display the resume form. We discuss the high level explanation of the Django app creation steps, check/test the create profile/resume html page and view, add url links to the profile page to help the user navigate to the profile-create and profile view pages, build the detail profile/resume page with Django class based views, work on the detail profile/resume page

Discussion on how to use the SLUG and absolute path url to get the URL path for for the Detailed Profile/Resume page, build the URL path for the detailed profile/resume view, we start testing the login work flow, change code so user is sent to the profile page after successful login, test entire User Registration Process, Login and Profile/Resume creation and View detailed page.

Discussion on compressing images for a web application, explaining the problem with large images, download the application used to compress images for web, adding a background image to HTML code, adding a background image to CSS code, discuss changes made to the resume detailed page, adding a bootstrap table Introduction in to Django app system emails, getting an email hosting account, setting up an email account on cPanel, adding email settings to the settings.py file, walkthrough HTML email template we will be using, python django code to send an email written inside of a view function, to send a test email, add a testing view route to test the django email code, adding images to to the HTML template ​

Integrate django HTML email to a view function for updating the user password logic, create a new functions.py file to move the send-email logic from a view function to a functions file, create a new view for forgot password - to illustrate how to incorporate sending an email to a view function, create a 'forgot' password django form to use with forgot password function to send users forgot email to users to reset password, work on the forgot.html page, update register view function to include functionality to send client an email when they create a new account, update the urls file to include new forgot url, test registration process with the added email functionality, test out functionality for forgot password, complete Education model and form - to complete resume page, replace class based view on the detailed resume page with a function based view, write the function view for the detailed resume page, that will include forms for education class on the same view function, add education form to detailed resume html page - using Bootstrap modal to display the form on a pop-up, check if education data was saved in the database, display education data on the detailed resume page, allow user to enter new education class data and see it on the same page that shows the resume class.

Section-4: Web Application Management

We start by extracting information from the website and pdf document using python PyPDF2 library parsing through a PDF document. We go through the code for downloading the PDF document from the internet using wget and command line inside of Python, write the code to use PyPDF2 to open and read the PDF document we just downloaded, web scrapping for the document links we need, download all the available PDF documents at once, parse the PDF document to extract the job data from the documents, summarise the code for extracting Job data from the PDF document, extracting and print out the job data from a single PDF document. We test the code for adding Job data from the PDF documents in to the database, run through all the files at once extracting data, we go through website scrapping code for getting Job data, test the code for web scrapping - print data on command line, extract data from webpage and add it to database instead of printing on command line, test the code we just built for web scrapping, fix the issue of replicating job data, remove duplicates from lists, add code to sort the job data in to different categories, before the data is added to the database, go through HTML for the Job list page - for displaying Job data in our website. We then test our app, first look at the results of our data scrapping, sorting out teething.

Extract Job Data from PDF and Other Websites to Populate Database Part 2

Extract Job Data from PDF and Other Websites to Populate Database Part 3

In this lecture we cover how to get your API keys from twitter, virtual Machine (VPS) discussion, how to get a digital ocean droplet for your twitter bot, set up python development environment, folders, etc. We create Hello World Twitte Bit code, minimal requirements to use the Tweepy Library with Twitte API, go through tweepy documentation reference for the API object, listing all available methods, testing our first API code, printing tweets from your timeline and other public timelines, check your API access limits, how to save the data you get from twitter in a Json file, how to send a text-only tweet and image tweet, how to include an emoji inside a tweet, add a tweet with an image, how to transfer an image (or any file) from your personal computer to the VPS (Droplet). We also go through code for sending a tweet with an image, discuss the second part of this lecture - how to apply what we have learned to tweet our JOB data from Django app, build the scrapper for job websites to get the data we need for the tweets, explore the URL Shortening service we will be using, create an an account to get started, install BeautifulSoup and Requests, get data from our PDF documents to use in Job tweets, use job data in JSON format to create a tweet string, data clean up, python main file - code fo sending tweets with job data.

We create function to grab popular hashtags from Twitter API, based on you region - or any region by inputing longitude/latitude, discuss the final tweet function and how we add hashtags to our tweets, while ensuring the string length is less that 160 characters and finally use the Python Schedule Library to schedule code to run at specific times, we will use this to schedule our tweets.

We create the form for the search function on home page, edit the home view function to process search form, edit home page HTML file to display search form, runserver to test the search function, refine search function to return results for more than one word, test search function again.

We review final website, recap digitalocean tutorial for deploying django website, update settings file to add new allowed hosts, edit DNS records of domain host to current VPS, check that we can use gunicorn to run our web app, follow the rest of the tutorial for deployment with gunicorn, set up nginx to serve our web app, check to see our website running, install certbot for SSL certificates and install an SSL for our website, our final website uploaded.

Section-5: Bonus Lecture

We are going to answer the questions (1) What is Django, Where did Django come from, (2) Describe Django origins, (3) Name some real life applications built on Django, (4) What are some features of Django, (5) Django admin panel, (6) Code reusability feature of Django, how does it work, (7) Why is Django called a loosely coupled framework, (8) What is the significance of the settings.py file, (9) Describe the Django Architecture, how does Django work, (10) How is the data in Django app stored, (11) How do you do static file management in Djang, (12) Technical questions, project portfolio discussion and how to prepare for this, (13) How does Django compare to Flask and (14) More Django reading, book recommendations

About Instructor

Bertha  Kgokong

Bertha Kgokong

Software Programmer and Tech Entrepreneur

Software Programmer and Tech Entrepreneur, i have extensive experience in Software Development - end-to-end in most platforms, Business Processes and Entrepreneurship. I am a fully qualified Engineer, with a Bachelors Degree and Masters in Business Administration - with over 17 years of professional experience. I am also an entrepreneur with a couple of award winning ventures and projects in Software Development.