Libraries linked in this lesson:
Real Python Resources:
Libraries linked in this lesson:
Real Python Resources:
00:00 In the previous lesson, I gave an overview of the course. In this lesson, I’ll start section one talking about typical software projects you can create in the Python domain.
00:10 When you visit a web page somewhere, a server is turning your URL request into some HTML content. That server might be running Python. There’s a wide variety of approaches where some servers output HTML code directly for the browser, while others are single-page applications that download a JavaScript application to the browser.
00:32 Single-page applications still need to communicate with the server through an API and the code for that API can also be in Python. Native mobile development often takes this approach as well, with web technologies happening on the server side that the mobile communicates with.
00:49 This is still one of the largest segments of Python work and has a fairly high level of job demand. There are a number of different frameworks out there each with their pros and cons.
00:59 Let me quickly show you one of the more popular ones, Django. This is a simple website from a course on writing APIs for the web. This page is straight HTML, but then when I click on the Peru link, this page is a mix.
01:14 It starts out with HTML to build it, but then I can reorganize items in the schedule by dragging them around.
01:22 This uses an API to update the positional information in the database on the server. Same goes with the add and delete buttons. This example is built on a framework called Django.
01:35 One of Django’s superpowers is that it includes both web and database tools and comes with an admin utility for managing things you store in the database.
01:48 That’s another thing that Django gives you out of the box—authentication management. Let me sign in. This is a small project. It only has four kinds of things in the database.
02:01 Users and Groups are part of the authentication module, while Entries and Timelines are my objects in the database. If I click on Entries, I see a list of all the entries.
02:12 Some of these were in the Peru page I showed you before. If I click on one of the entries, I get the fields for this record in the database. I can edit this, add new records, or delete it. All this comes almost for free.
02:27 If you’ve written the code to declare what your database objects look like, it only takes an extra line or two to register that same object in this admin tool.
02:37 Some really famous places out there use Django, like Pinterest, YouTube, and one of my favorite places, The Onion.
02:45 So just what kind of tools are out there? The site I just demoed was built using the Django framework. When you write code for the web, you typically need a view that’s code that generates a page, a route, that’s a thing that ties a URL to your view, and often you’ll need somewhere to store your data like a database.
03:03 An object-relational mapping is an object-oriented mechanism for accessing that database. Django comes with all this and more out of the box. Because Django comes with so much, it can be overkill for certain kinds of projects.
03:18 If you only need to build an API, then FastAPI might be the right choice for you. It uses Python type hints to declare what values a function takes and automatically generates an API based on the registered functions.
03:32 The library is so popular that it’s even spawned clones. Django Ninja is a library that adds FastAPI-like functionality to a Django project.
03:43 Flask is a lightweight web framework that’s similar to Django. It concentrates on the views and routes parts of things, but there are plenty of third-party add-ons to provide authentication and other features.
03:54 Personally, my default is Django because if you’re building a full site, you’re going to need a lot of Flask add-ons, which in the end are just doing what Django does.
04:04 But if I need to quickly put something together for testing, nothing beats Flask to get something going in a flash. Tornado is fast, I mean really fast. Although it’s considered a web framework, typically it gets used as an endpoint.
04:19 If you need to scale an API to crazy performance levels, Tornado might be the library for you.
04:26 Real Python has lots of content on web development, and this first link is a list of tutorials to help you dig in. Clickable versions of the links shown on these slides are below in the notes.
04:37 For Django-specific tutorials, see this list,
04:41 and this tutorial is a hands-on project that shows you how to build a resume site to show off your skills. There’s also a topic list of Flask tutorials, and this tutorial covers how to use FastAPI.
Become a Member to join the conversation.