Home Web Development Django 4 for the Impatient

Django 4 for the Impatient

By Greg Lim , Daniel Correa
books-svg-icon Book
Subscription FREE
eBook + Subscription $15.99
eBook $24.99
Print + eBook $30.99
READ FOR FREE Free Trial for 7 days. $15.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
READ FOR FREE Free Trial for 7 days. $15.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
Subscription FREE
eBook + Subscription $15.99
eBook $24.99
Print + eBook $30.99
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
  1. Free Chapter
    Chapter 2: Understanding the Project Structure and Creating Our First App
About this book
Learning Django can be a tricky and time-consuming activity. There are hundreds of tutorials, loads of documentation, and many explanations that are hard to digest. However, this book enables you to use and learn Django in just a couple of days. In this book, you’ll go on a fun, hands-on, and pragmatic journey to learn Django full stack development. You'll start building your first Django app within minutes. You'll be provided with short explanations and a practical approach that cover some of the most important Django features, such as Django Apps’ structure, URLs, views, templates, models, CSS inclusion, image storage, authentication and authorization, Django admin panel, and many more. You'll also use Django to develop a movies review app and deploy it to the internet. By the end of this book, you'll be able to build and deploy your own Django web applications.
Publication date:
June 2022
Publisher
Packt
Pages
190
ISBN
9781803245836

 

Chapter 1: Installing Python and Django

Welcome to Django 4 for the Impatient! This book focuses on the key tasks and concepts to help you to learn and build Django applications fast. It is designed for readers who don't need all the details about Django except for concepts that you really need to know. By the end of this book, you will be confident creating your own Django projects.

So, what's Django? Django is a free, open source web framework for building modern Python web applications. Django helps you quickly build web apps by abstracting away many of the repetitive challenges involved in building a website, such as connecting to a database, handling security, enabling user authentication, creating URL routes, displaying content on a page through templates and forms, supporting multiple database backends, and setting up an admin interface.

This reduction in repetitive tasks allows developers to focus on building a web application's functionality rather than...

 

Technical requirements

In this chapter, we will be using Python 3.8+ and pip.

The code for this chapter is located at https://github.com/PacktPublishing/Django-4-for-the-Impatient/tree/main/Chapter01/moviereviews.

 

Understanding the app we will be building

For our project, we will be building a movie reviews app that will allow users to view and search for movies, as shown in Figure 1.1:

Figure 1.1 – A home page with search functionality

Users will also be able to log in and post reviews of any movies they may have watched, as shown in Figure 1.2:

Figure 1.2 – A movie page listing reviews

They will be able to type in and add their review, as shown in Figure 1.3:

Figure 1.3 – An interface for writing a review

Users can see the list of reviews on a movie's page and post, edit, or delete their own review if they are logged in. They will not be able to edit or delete other users' reviews though. Through building this app, we will learn a lot of concepts, such as forms, user authorization, permissions, foreign keys, and more.

Let's begin by installing Python and Django.

 

Installing Python

First, let's check whether we have Python installed and, if so, what version we have.

If you are using a Mac, open your Terminal. If you are using Windows, open Command Prompt. For convenience, I will refer to both Terminal and Command Prompt as Terminal throughout the book.

We will need to check whether we have at least Python 3.8 in order to use Django 4. To do so, go to your Terminal and run the following commands.

For macOS, run this:

python3 --version

For Windows, run this:

python --version

This shows the version of Python you have installed. Make sure that the version is at least 3.8. If it isn't, get the latest version of Python by going to https://www.python.org/downloads/ and installing the version for your OS. For Windows, you must select the Add Python 3.* to PATH option, as shown in Figure 1.4:

Figure 1.4 – Install Python on Windows

After the installation, run the command again to check the...

 

Installing Django

We will be using pip to install Django. pip is the standard package manager for Python to install and manage packages not part of the standard Python library. pip is automatically installed if you downloaded Python from https://www.python.org/.

First, check whether you have pip installed by going to the Terminal and running the following.

For macOS, run this:

pip3

For Windows, run this:

pip

If you have pip installed, the output should display a list of pip commands. To install Django, run the following command:

For macOS, run this:

pip3 install Django==4.0

For Windows, run this:

pip install Django==4.0

The preceding command will retrieve the latest Django code and install it on your machine. After installation, close and reopen your Terminal.

Ensure you have installed Django by running the following commands.

For macOS, run this:

python3 -m django

For Windows, run this:

python -m django

Now, the output will show...

 

Running the Django local web server

In the Terminal, cd into the created folder:

cd moviereviews

Then, run the following.

For macOS, run this:

python3 manage.py runserver

For Windows, run this:

python manage.py runserver

When you do so, you start the local web server on your machine (for local development purposes). There will be a URL link: http://127.0.0.1:8000/ (equivalent to http://localhost:8000). Open the link in a browser and you will see the default landing page, as shown in Figure 1.6:

Figure 1.6 – The landing page of the Django project

This means that your local web server is running and serving the landing page. Sometimes, you will need to stop the server in order to run other Python commands. To stop the local server, press Ctrl + C in the Terminal.

 

Summary

In this chapter, you learned how to install and use Python, pip, and Django. You also learned how to create a new Django project and run a Django local web server. In the next chapter, we will look inside the project folder that Django has created for us to understand it better.

About the Authors
  • Greg Lim

    Greg Lim is a technologist and the author of several books on programming. He has taught programming in tertiary institutions for many years and places a strong emphasis on learning by doing. Follow Greg on Twitter at greglim81.

    Browse publications by this author
  • Daniel Correa

    Daniel Correa is a researcher, software developer, and author of programming books. He has a PhD in computer science. He is a professor at Universidad EAFIT in Colombia. He is interested in software architectures, frameworks (such as Laravel, Nest, Django, Express, Vue, React, and Angular), web development, and clean code. Follow Daniel on Twitter at danielgarax.

    Browse publications by this author
Latest Reviews (1 reviews total)
Copre tutte le fasi essenziali della creazione di un'app per il web e riesce ad essere nello stesso tempo esaustivo e sintetico. Penso che sia l'ideale per chi, come me, vuole farsi un'idea dello strumento per decidere se adottarlo.
Django 4 for the Impatient
Unlock this book and the full library FREE for 7 days
Start now