Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Django 5 for the Impatient
Django 5 for the Impatient

Django 5 for the Impatient : Learn the core concepts of Django to develop Python web applications , Second Edition

Arrow left icon
Profile Icon Daniel Correa Profile Icon Greg Lim
Arrow right icon
S$12.99 S$37.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (2 Ratings)
eBook Sep 2024 228 pages 2nd Edition
eBook
S$12.99 S$37.99
Paperback
S$47.99
Subscription
Free Trial
Arrow left icon
Profile Icon Daniel Correa Profile Icon Greg Lim
Arrow right icon
S$12.99 S$37.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (2 Ratings)
eBook Sep 2024 228 pages 2nd Edition
eBook
S$12.99 S$37.99
Paperback
S$47.99
Subscription
Free Trial
eBook
S$12.99 S$37.99
Paperback
S$47.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Django 5 for the Impatient

Understanding the Project Structure and Creating Our First App

Django projects contain a predefined structure with some key folders and files. In this chapter, we will discuss the Django project structure and how some of those folders and files are used to configure our web applications. Furthermore, Django projects are composed of one or more apps. We will learn how to create a “home” app, composed of “home” and “about” sections, and how to register it inside our Django project.

In this chapter, we will cover the following topics:

  • Understanding the project structure
  • Creating our first app
  • Creating a home page
  • Creating an about page

With all of these topics completed, you will know how to create Django apps and web pages.

Technical requirements

In this chapter, we will be using Python 3.10+. Additionally, we will be using the Visual Studio (VS) Code editor in this book, which you can download from https://code.visualstudio.com/.

The code for this chapter is located at https://github.com/PacktPublishing/Django-5-for-the-Impatient-Second-Edition/tree/main/Chapter02/moviesstore.

The CiA video for this chapter can be found at https://packt.link/rzU25

Understanding the project structure

Let’s look at the project files that were created for us in Chapter 1, in the Creating and running a Django project section. Open the moviesstore project folder in VS Code. You will see the elements shown in Figure 2.1:

Figure 2.1 – The MOVIESSTORE directory structure

Figure 2.1 – The MOVIESSTORE directory structure

Let’s learn about each of these elements.

The moviesstore folder

As you can see in Figure 2.1, there is a folder with the same name as the folder we opened in VS Code originally – moviesstore. The moviesstore folder contains a set of files to configure the Django project. Figure 2.2 shows the content of the moviesstore folder:

Figure 2.2 – The moviesstore folder content structure

Figure 2.2 – The moviesstore folder content structure

Let’s briefly look at all the elements under the moviesstore folder:

  • __pycache__: This folder stores compiled bytecode when we generate our project. You can largely ignore this folder. Its purpose...

Creating our first app

A Django app is a self-contained package of code that performs a specific functionality or serves a particular purpose within a Django project.

A single Django project can contain one or more apps that work together to power a web application. Django uses the concept of projects and apps to keep code clean and readable.

For example, on a movie review site such as Rotten Tomatoes, as shown in Figure 2.4, we can have an app for listing movies, an app for listing news, an app for payments, an app for user authentication, and so on:

Figure 2.4 – The Rotten Tomatoes website

Figure 2.4 – The Rotten Tomatoes website

Apps in Django are like pieces of a website. You can create an entire website with one single app, but it is useful to break it up into different apps, each representing a clear function.

Our Movies Store site will begin with one app. We will later add more as we progress. To add an app, in the Terminal, stop the server by pressing Cmd+ C. Navigate...

Creating a home page

Creating a simple page or section in Django usually involves three steps:

  1. Configure a URL.
  2. Define a view function or class.
  3. Create a template.

Let’s see how to apply those steps to create a simple “home” page that will display a “welcome” message to the final user.

Configuring an URL

Django URLs (Uniform Resource Locators) are patterns used to map incoming HTTP requests to the appropriate view functions or classes that handle those requests. They define the routing mechanism for your Django project, specifying which views should be called for different URLs.

There is a main URL configuration file located at /moviesstore/urls.py that currently has the following code:

…
from django.contrib import admin
from django.urls import path
urlpatterns = [
    path('admin/', admin.site.urls),
]

When a user types a URL (related to our Django application) in the browser...

Creating an about page

Now that we learned how to create a simple page, let’s repeat the process to create the about page. We will follow these three steps:

  1. Configure the about URL.
  2. Define the about function.
  3. Create the about template.

Let’s start.

Configuring the about URL

In /home/urls.py, add the following path in bold:

from django.urls import path
from . import views
urlpatterns = [
    path('', views.index, name='home.index'),
    path('about', views.about, name='home.about'),
]

So, if a URL matches the /about path, it will execute the about function defined in the views file.

Defining about function

In /home/views.py, add the following in bold:

from django.shortcuts import render
def index(request):
    return render(request, 'home/index.html')
def about(request):
    return render(request, ...

Summary

In this chapter, we discussed the Django project structure. We analyzed some of the most important project folders, files, and their functionalities. We saw how a web project can be composed of several applications, and we learned how to create a Django app. We also learned how URLs, views, and templates connect to create web pages. We created a couple of pages and loaded them into our local web server. In the next chapter, we will see how to improve the look and feel of our Django applications by using base templates and a CSS framework.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Develop web applications with Python and Django quickly
  • Understand Django features with concise explanations and learn how to use them in a practical way
  • Create a movie store app with a responsive user interface and deploy it to the cloud
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Learning Django can be a challenging and time-consuming activity without the right guidance. With hundreds of tutorials, loads of documentation, and unclear explanations out there, it’s easy to lose sight of what’s most important. This book stands out by teaching you how to use Django in just a few days with a focused approach. In this second edition, you’ll go on a fun, practical, and pragmatic journey to learning full-stack development with Django 5. You’ll start building your first Django app within minutes. As you progress, you’ll learn from concise explanations that will help you get to grips with some of the most important Django features, including URLs, views, templates, models, CSS inclusion, image storage, Django admin panel, and more. You’ll also understand how to design Django MVT (Model-View-Template) architectures and implement them. Additionally, you’ll use Django to develop a movie store application 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 confidently.

Who is this book for?

This book is for Python developers of any experience level who want to build full-stack web applications using Django. Anyone new to Django can get started with this book.

What you will learn

  • Understand and use Django key features, including URLs, templates, models, and forms
  • Implement responsive user interfaces using Bootstrap
  • Manage data storage in databases effectively
  • Explore the powerful built-in admin interface with Django
  • Harness Django's powerful built-in authentication system
  • Deploy your Django project on the internet for users

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 27, 2024
Length: 228 pages
Edition : 2nd
Language : English
ISBN-13 : 9781835468333
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 27, 2024
Length: 228 pages
Edition : 2nd
Language : English
ISBN-13 : 9781835468333
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total S$ 169.97
Python Natural Language Processing Cookbook
S$60.99
Django 5 for the Impatient
S$47.99
Python Data Cleaning and Preparation Best Practices
S$60.99
Total S$ 169.97 Stars icon
Banner background image

Table of Contents

15 Chapters
Chapter 1: Installing Python and Django, and Introducing the Movies Store Application Chevron down icon Chevron up icon
Chapter 2: Understanding the Project Structure and Creating Our First App Chevron down icon Chevron up icon
Chapter 3: Designing a Base Template Chevron down icon Chevron up icon
Chapter 4: Creating a Movies App with Dummy Data Chevron down icon Chevron up icon
Chapter 5: Working with Models Chevron down icon Chevron up icon
Chapter 6: Collecting and Displaying Data from the Database Chevron down icon Chevron up icon
Chapter 7: Understanding the Database Chevron down icon Chevron up icon
Chapter 8: Implementing User Signup and Login Chevron down icon Chevron up icon
Chapter 9: Letting Users Create, Read, Update, and Delete Movie Reviews Chevron down icon Chevron up icon
Chapter 10: Implementing a Shopping Cart System Chevron down icon Chevron up icon
Chapter 11: Implementing Order and Item Models Chevron down icon Chevron up icon
Chapter 12: Implementing the Purchase and Orders Pages Chevron down icon Chevron up icon
Chapter 13: Deploying the Application to the Cloud Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(2 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
N/A Nov 08, 2024
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Feefo Verified review Feefo
J Adrian Verkouteren Oct 26, 2024
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I finished the book and successfully completed the project, but I do not understand how template_data works on p. 51, etc. How flexible is it? How many different lines can one add? Which DB Fields are off limits?I also need to figure out how to combine a string prefix to a DB field value to use as a link as a loop iterates to use the name of an image as a url link to the image.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.