Home Page Icon
Home Page
Table of Contents for
III. Implementing a Full-Featured Website
Close
III. Implementing a Full-Featured Website
by Brad Dayley
Sams Teach Yourself Django in 24 Hours
Copyright
Dedication
About the Author
Acknowledgments
We Want to Hear from You!
Reader Services
Introduction
Who Should Read This Book
How This Book Is Organized
How to Use This Book
I. Creating the Website Framework
1. Understanding Django
What Is Django?
Why Use Django?
Understanding Models
Understanding Views
Understanding Templates
Configuring the settings.py File
Using the manage.py Utility
Understanding the Django Development Server
Understanding the Admin Interface
Admin Model View
Admin Change List View
Admin Form View
Installing Django
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
2. Creating Your First Website
Creating a Django Project
Starting the Development Server
Configuring the Database
Configuring Database Access in settings.py
Synchronizing the Project to the Database
Installing an Application
Creating a Model
Adding Data Using the API
Setting Up the URLConf File
Creating a Simple View
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
3. Adding Models and Objects to Your Website
Installing the Admin Interface Model
Updating the URLconf File to Allow Admin Access
Activating the Model in the Admin Interface
Adding, Modifying, and Viewing Objects in the Admin Interface
Defining Data Models
Understanding Field Types
Text Fields
Date and Time Fields
EmailField
File Fields
URLField
Adding Field Options to a Field Type
null and blank Field Options
default Field Option
choices Field Option
core Field Option
editable Field Option
primary_key Field Option
unique Field Options
Adding Relationships to Models
Many-to-One Relationships
Many-to-Many Relationships
One-to-One Relationships
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
4. Creating the Initial Views
Setting Up the URLconf File
Understanding the HttpRequest and HttpResponse Classes
Retrieving Information from a Web Request Using the HttpRequest Object
Displaying a Web Page Using the HttpResponse Object
Configuring the URL Patterns
Adding URL-Based Arguments to the Views
Adding Expressions to URL Patterns
Using the Expression Values in the View
Adding Argument Names to Expressions
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
II. Implementing the Website Interface
5. Using Data from the Database in Views
Adding Data to the Database
Accessing Data in the Database
Retrieving All Objects
Retrieving One Object
Modifying Data in the Database
Performing Queries in the Database
Using the filter() Function
Using the exclude() Function
Understanding Field Lookups
Chaining QuerySets
Ordering Objects in a QuerySet
Adding Data in a Model to a View
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
6. Configuring Web Page Views
Passing Extra Options to a View
Using View Prefixes
Using Additional URLconf Files
Calling the View Functions Directly
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
7. Implementing Django Templates to Create Custom Views
Configuring the Template Directory
Creating a Template
Creating Templates in the Django Shell
Creating HTML Templates
Accessing Objects Using HTML Templates
Rendering a Template as an HTTP Response
Extending Templates
Embedding Templates
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
8. Using Built-in Template Tags to Enhance Views
Implementing Loops
Implementing if Logic
Using if
Using ifchanged
Using ifequal
Using ifnotequal
Adding Links with the url Tag
Reducing Code Using the with Tag
Adding Cycle Logic to Tables
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
9. Using Built-in Template Filters to Enhance Views
Understanding Filters
Formatting Text
Changing Text Case
escape
length
linebreaks
stringformat
striptags
wordwrap
pluralize
yesno
Manipulating Lists
slice
make_list
join
random
Sorting Dictionaries
Formatting Dates
date
time
now
timesince and timeuntil
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
10. Adding Forms to Views
Creating Form Instances
Form Fields
Bound and Unbound Forms
Rendering Forms as HTML
Rendering Forms as a Table
Rendering Forms as a List
Rendering Forms as Paragraphs
Rendering Forms from Models
Creating a Form from a Model
Creating a Form from an Object
Creating Partial Forms from Models
Customizing Forms
Customizing Widgets
Customizing Forms in Templates
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
11. Using Views to Add and Update Data in the Database
Handling GET and POST Requests
Validating Data from a POST Against the Model
Retrieving Data from a POST
Validating the Data from a POST
Handling Errors in the POST Data
Accessing Clean Data in the Form
Updating Data in the Database
Adding Data to the Database
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
12. Utilizing Generic Views
Understanding Generic Views
Arguments Dictionary
URL Pattern
Context Variables
Generic HTML Template
Using Simple Generic Views
direct_to_template
redirect_to
Displaying an Object List in a Generic View
Displaying Object Details in a Generic View
Displaying Date-Based Objects in a Generic View
archive_index
archive_year
archive_month
archive_week
archive_day
archive_today
archive_detail
URL Patterns for Date-Based Views
Using Generic Object-Creation Views
Using Generic Object-Update Views
Using Generic Object-Deletion Views
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
13. Advanced View Configurations
Loading Templates from Applications
Extending the Template System
Creating Custom Filters
Creating Custom Tags
Creating Simple Custom Tags
Creating Custom Block Tags
Retrieving and Setting Variables in the Context
Inclusion Tags
Understanding How to Use RequestContexts in Templates
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
III. Implementing a Full-Featured Website
14. Managing Site Users
Adding Users
Understanding User Objects
Anonymous Users
Creating User Objects in Views
Changing User Passwords in Views
Adding Groups
Setting User Permissions
Basic Permissions
Creating Custom Permissions
Adding Permissions to Users and Groups
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
15. Adding Website Security
Implementing User Logins
Adding Logout Functionality
Verifying Authentication
Verifying Authentication in View Functions
Verifying Authentication in Templates
Verifying Permissions
Verifying Permissions in View Functions
Verifying Permissions in Templates
Limiting Access to Generic Views
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
16. Managing Sessions and Cookies
Understanding Django’s Session Framework
Configuring the Session Manager
Using Django’s Test Cookies
Setting and Retrieving Session Data
Setting and Retrieving Cookies
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
17. Customizing Models in the Admin Interface
Customizing the Model Change List
Setting Fields to Display
Adding a Date Hierarchy
Ordering Objects in the Change List
Adding Search Fields
Customizing the Model Form
Viewing Multiple Models Inline
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
18. Customizing the Admin Interface
Overriding Admin Templates at the Site Level
Creating Custom Admin Views
Overriding the Admin Templates at the Application or Object Level
Overriding Block Tags in a Custom Admin Template
Overriding the Built-in Admin Views in the URLconf File
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
IV. Implementing Advanced Website Components
19. Implementing Middleware
Installing Middleware
Implementing Middleware Applications
Implementing a Request Preprocessor
Implementing a View Preprocessor
Implementing a Response Postprocessor
Implementing an Exception Postprocessor
Django’s Built-in Middleware
django.middleware.common.CommonMiddleware
django.contrib.sessions.middleware.SessionMiddleware
django.contrib.auth.middleware.AuthenticationMiddleware
django.middleware.cache.CacheMiddleware
django.middleware.gzip.GZipMiddleware
django.middleware.locale.LocaleMiddleware
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
20. Internationalization and Localization
Localizing Strings in Python
Standard Translation
Lazy Translation
No-op String Translation
Localizing Strings in Templates
The trans Tag
The blocktrans Tag
Using Translation Hooks in Tags
Accessing Languages in a Template
Creating Language Files
Using make-messages
Translating Messages
Using compile-messages
Setting Language Preference
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
21. Creating Sitemaps
Creating a Sitemap
Creating a Sitemap Class
Enabling the Sitemap
Creating a Sitemap of Generic Views
Creating a Sitemap Index
Pinging Google
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
22. Implementing Multiple Websites
Implementing the sites Framework
Installing the sites Framework
Assigning Content to Multiple Sites
Assigning Content to a Single Site
Accessing the Site from Views
Using the CurrentSiteManager Class
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
23. Configuring Caching
Configuring Caching Backends
Database Backend
File System Backend
Local Memory Backend
Simple Backend
Dummy Backend
Memcached Backend
Implementing a Per-Site Cache
Implementing a Per-View Cache
Implementing a Per-Object Cache
Managing Upstream Caching
Allowing Cached Pages to Vary Based on Headers
Controlling Cached Pages Using the Cache-Control Header
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
24. Deploying Django
Deploying Django to Apache with mod_python
Python, Django, a Database, Apache, and mod_python
Placing the Project in PYTHONPATH
Configuring Your Django Project
Adding Admin Media Files to the Server
Setting up the httpd.conf File
Other Deployment Configurations
Implementing Multiple Django Installations in Apache
Serving Media Files on the Same Server
Configuring Eggs with mod_python
Optimizing Django Deployment
Database on a Separate Server
Media on a Separate Server
Using Only Necessary Middleware
Implementing Caching
Adding RAM
Summary
Q&A
Workshop
Quiz
Quiz Answers
Exercises
Appendixes
A. Django Resources
Django
Python
Python Imaging Library (PIL)
Apache
mod_python
flup
FastCGI
PostgreSQL Database
MySQL
SQLite 3
Microsoft SQL Server
Oracle
Subversion
B. Django Form Field Objects
Field Objects
BooleanField
CharField
ChoiceField
DateField
DateTimeField
DecimalField
EmailField
FileField
ImageField
IntegerField
IPAddressField
MultipleChoiceField
NullBooleanField
RegexField
TimeField
URLField
Widget Objects
Form Field to Model Field Mapping
C. Formatting Dates and Times
Try It Yourself
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
13. Advanced View Configurations
Next
Next Chapter
14. Managing Site Users
Part III. Implementing a Full-Featured Website
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset