Are you new to Python and are yet to explore all that it can do? Yes, Python has more to it than just data science and application programming. With the help of frameworks like Flask and Django, it can also build scalable web applications. The following are some popular web applications that are majorly written using Python or Django:
Python has two powerful frameworks: Flask and Django. The question is which framework should we choose? A common route is to begin building small, interesting projects with a simple framework, like Flask, and move on to Django as you begin to grasp the basics.
This Learning Path is designed to mold you to a complete Python web developer.
Yes, this is not a course; it is a Learning Path.
What this essentially means is that it contains multiple video courses that are logically tied together to provide you with a larger learning curve.
Let’s dig into what this Learning Path does. Since you already know the basics of Python, you are no stranger to the fact it is an immensely powerful language. With the basics in place, this Learning Path takes a hands-on approach and demonstrates how to build fully functional real-time applications from scratch. The Learning Path begins with building interesting projects with Flask, gradually introduces the more challenging framework—Django—and then moves on to the complex concepts in it. It covers concepts such as how to build up and structure an effective web API that can be used by any client application accessing it over the HTTP protocol, and how to use the Flask and Django ecosystem efficiently to create web applications.
So after completing this Learning Path, you should be able to create web applications as good as any of the popular applications mentioned above. Yay!
About the author:
For this Learning Path, we have combined the best works of five extremely esteemed authors: Gergo Bogdan, Alexander Putilin, Jack Stouffer, Matthew Nuzum, and Kevin Veroneau.
Alexander Putilin is a professional programmer and has several years of experience in languages such as Python and C++. He has worked for a lot of years in specializing in Internet-related services and products. He has also worked in the Search Engine department.
Jack Stouffer is a programmer who has several years of experience in designing web applications. He switched to Flask three years ago for all his projects.
Matthew Nuzum has been developing web applications since 1999 and has worked for several start-ups including Canonical, the makers of Ubuntu, as well as Fortune 500 companies. He has a passion for helping others learn new technologies and has written numerous tutorials and help documents as well as running a web-focused user group based in his hometown.
Kevin Veroneau is a very active Python and Django developer who has worked for many start-ups, has an active Python blog, and has worked on a magnitude of Python projects over the years.
The aim of this video is to present how to create a Flask development environment, how to install Flask, how to create a simple web API, and how to run the project.
In order to create a nicely usable and developer-friendly web API, we need to be able to define separate access paths for the assets that we want to manage through the web API. These paths can be configured by defining custom routing inside Flask.
The goal of this video is to give an overview of Flask's template support.
In this video, we will review how to send messages from the server-side to templates (flash messages) and how to define and map custom error pages.
The purpose of this video is to present the basic concepts behind CRUD operations and the REST software architecture style.
The purpose of this video is to present SQLAlchemy, Python’s well-known ORM package, present the new data model for our project and present how to use SQLAlchemy in Python with the MySQL database engine.
This video aims at presenting how to implement the Create operation (from CRUD) using Flask and SQLAlchemy, and how to apply best practices to Create.
The aim of this video is to present how to implement the Read operation from CRUD using SQLAlchemy and Flask.
In this video, we aim to cover how to implement the Update operation from CRUD using Flask and SQLAlchemy as a RESTful API.
In this video, we are going to cover how to implement the Delete CRUD operation using Flaks and SQLAlchemy.
In this video, we are going to take a look at an advanced topic of REST, Hypermedia, and HATEOAS; these decouple the client and server application architecture.
In this video, we are going to cover why it is useful to have paginated data.
In this video, we are going to cover how to implement authentication in RESTful APIs.
In this video, we are going to take a look at how to improve the response time of your API by applying different types of caching.
In this video, we will review the best practices for handling errors within our restful API.
The aim of this video is to cover the design guidelines that should be taken into account when building large applications/APIs using Flask.
The aim of this video is to present why HTTPS should be used for APIs.
The aim of this video is to present how Token Authentication can be implemented using Flaks.
The aim of this video is to present how to manage cookies in a Flask application.
The aim of this video is to present how passwords should be stored within a web application.
The aim of this video is to present the Flask test client and how can it be used for application testing.
The aim of this video is to present how we can test different routes using the Flask Test Client.
The aim of the video is to present how to use the Flask Test Client for testing CRUD operations.
The aim of this video is to present how an authentication layer of our Flask application can be tested using Flask Test Client.
The viewer needs to have a clear picture of where this course is going to take them.
The course assumes an understanding and familiarity of Flask's API, but we still need a basic application to build off.
Python libraries are installed globally, so we need a way to isolate our project's libraries so that they do not conflict with each other.
Connecting to and querying databases can be verbose
We have a universal connection. But now we need to create an API to make the queries.
We have a universal connection and have set up a universal query interface. Let's start reading data.
Data is rarely isolated. We need a way to match the records of relationship A to the records of relationship B in such a way that a record in relationship A can link to multiple records in relationship B, but a record in B is linked to only one record in A.
We need a way to match relationship A and relationship B in such a way that a record in relationship A can link to multiple records in relationship B and vice versa.
How can SQLAlchemy represent the more complex queries that can be created in SQL?
Jinja provides an easy way to replace values in an HTML document, but to structure dynamic pages, our Jinja templates need control logic.
Creating secure forms that cover all of the validation issues in web forms involves a lot of boilerplate code.
Many of our routes contain common attributes. We need an easy way to share this attributes between them.
Our app is getting larger. We need a way to split our app.py file into multiple files.
Our site is fully functional, but we can't have any user-added content, such as comments, without a user system.
In this video, we're going to cover how to handle encrypted passwords.
In this video, we're going to make our new login system accessible to users from the frontend.
In this video, we are going to add functionality to our app that allows us define where each user can and cannot go.
The aim of this video is to cover a basic overview of RESTful APIs.
In this video we're going to create REST API using Flask-RESTful.
Our app needs a way for maintainers of the site to edit and administer the site from the Web. We will provide this functionality with Flask Admin.
The only way to create new data in the database currently is to use the shell interface. We need an administrator interface to add data from the Web.
Currently, in all the places where movie posters or actor pictures should be, there are placeholder images. Let's fix that with Flask Admin.
When developing the app, we don't have a way of viewing the internals of Flask without a lot of print statements.
Currently, our app renders a template every time a page is loaded, even though the data on the page doesn't change that often.
One easy way to speed up page load times is to concatenate our CSS and JS files in one file each. But this process can be tedious to do manually.
Some functions or features in our application are too slow to run in the same process as our Flask server.
Now that Celery is set up, we need to understand how to send it commands.
Now that we understand how Celery works and how to give it a task, we will apply this knowledge for something practical.
Our application has a lot of code in it now; we need to make sure that our code isn't buggy without manually testing every change.
Now that we understand how unit tests work, let's build some tests for our SQLAlchemy models.
We now understand how to use the unittest library; next, we need to understand Python's test client.
Now that we are testing a lot of our application, we need a way to easily know what parts of our application are not being tested.
Our app needs a way to recreate a virtual environment on a remote machine. It also needs a way to upgrade packages.
We need to figure out how to deploy our app to a VPS
We need a way to figure out how to deploy our app to AWS.
We need a way to figure out how to deploy our app to Heroku.
Our app may need potential improvements. These improvements are up to learners to implement. We also should mention some practices that we haven't focused on in the series.
Learn about the benefits of Django and how it helps developers work more efficiently.
To begin using Django for development, you need to install the tools required. Learn the best way to install Django and then create your first project.
Django makes it easy to reuse your code by separating it into apps. In fact, many features we'll use in this series are separate apps that we'll include in our project.
A model is a simple description of the data you want to store. Some projects may need nothing more than a model.
The admin interface allows you to manage users, groups, and all the data stored in your database.
Views allow you to create web pages for your application. These pages can be plain HTML or can load data from your database.
Templates in Django can be standard HTML, XML, or plain text. This makes them simple to use for developers and designers.
Many of the web pages follow a common pattern: show simple HTML, show a list of records in the database, or show details about one record. Django's generic views simplify these common tasks.
Many of the web pages in your app share common components. We can use template inheritance to move these common pieces into a separate file in order to avoid repeating ourselves.
Django includes a simple but customizable authentication system that makes it easy to drop in a user database to your app.
It's quite common that your database structure will change over time. Django makes this easy with database migrations.
Nearly every application that has users needs to add custom fields to the user profile. Django provides tools to make this easy.
Some apps simply need to show user information from the database, but it's quite common to give users a way to add and change data. Django provides generic views for this very purpose.
The Django Debug Toolbar is an add-on app created by the Django community, which helps to look at what your web app is doing behind the scenes.
Django optimizes itself to do lazy loading, where data is loaded only when it's needed. In some common scenarios, this actually hurts performance. There is an easy solution though.
Generic Views can be subclassed and customized to enhance functionality. We'll use this capability to improve performance.
The Python community has created a standard called WSGI to deploy Python apps to the Web. It is compatible with many different kinds of servers.
Preparing our application for the Web involves a few simple steps in order to make it suitable for use in production.
In this example, we'll use Apache, uWSGI, and Django on an Ubuntu server. This stack is well supported and easy to use.
We've covered a lot of ground in a short time, which is possible because Django includes many time-saving capabilities.
Generic class-based views provide a lot of functionality. Let's take a look at how you can easily extend them to create your own custom solutions.
The built–in, generic class-based views are actually made up of many reusable mixins. Take a look at how you can use the same technique to add your own behaviors into your class-based views.
You don't have to use generic class-based views. If you plan to override much of the built-in behavior or just don't need it, then you can start out with a simpler class, such as view.
You can create a single class-based view that can handle all of the operations for a set of data. These are sometimes called switchboard classes, and they can help make your code easier to maintain.
Code that is used in many views can be moved into middleware, allowing it to operate either before or after your view code is executed.
Middleware classes are not fancy; they simply have one or more methods that correspond to one of the five predefined hooks available. Let's take a closer look at them here.
Showing users exceptions is unprofessional and may be a security problem. Let's examine an easier way to create middleware that catches and responds to unhandled exceptions.
In this video we will explore the possibility of creating custom filters to make frequently used behaviors easily reusable for everyone on our team.
If you need a functionality that is too sophisticated for a filter, it should be a template tag. These are of several kinds, such as simple_tag for basic functionality and a template inclusion tag to bring in entire templates.
With the growing popularity of Angular.js and similar tools, more applications need to provide a RESTful API. Tastypie is a Python module that does most of the work for us. Let's check it out.
Sometimes you want to modify the data before it goes out to the API. Tastypie makes it easy to add or customize the data returned from the API.
Not all applications work with a read-only API. Sometimes, you want full CRUD support from your API. You need to add an authentication step before you make this functionality available. Fortunately, Tastypie does all of this for us.
Sometimes, you want to combine data from different models. It's not hard to do this with Python, but generic relationships allow Django to do this for you.
Have you wished you could add or edit many records to the database at once? With only a few lines of code, you can add this capability to your application.
Django's ORM works fine when your filters are combined using the AND operator. If you want to perform more complicated queries, you should use the Q function, which just gives you more flexibility with your logic.
Is your application running slow? You may be performing expensive operations more often than necessary. We can use low-level caching operations to have tight control over our application's performance.
Do you have data that is accessed on many views? We already know we can create middleware to reduce duplication, but why not add caching at to middleware to also speed up performance?
If your cache needs are simpler, you can perform caching at the template level. This can provide a tremendous improvement in performance and is easy to use.
Do you frequently perform the same query and filter operation in multiple views? Avoid duplication using model managers.
You may have a similar logic in multiple areas of the site to deal with inserting data. You can create a manager function that accepts your data as a parameter and centralizes your insertion logic.
Do you perform regular maintenance on your application? You can simplify periodic cron tasks by creating custom manage.py commands.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.