售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Django: Web Development with Python
Table of Contents
Django: Web Development with Python
Django: Web Development with Python
Credits
Preface
What this learning path covers
What you need for this learning path
Who this learning path is for
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Module 1
1. Django's Position on the Web
From Web 1.0 to Web 2.0
Web 1.0
Web 2.0
What is Django?
Django – a web framework
The MVC framework
Why use Django?
Summary
2. Creating a Django Project
Installing Python 3
Installing Python 3 for Windows
Installing Python 3 for Linux
Installing Python 3 for Mac OS
Installing setuptools
Installing setuptools for Windows
Installing setuptools for Linux
Installing setuptools for Mac OS
Installing PIP
Installing PIP for Windows
Installing PIP for Linux
Installing PIP for Mac OS
Installing Django
Installing Django for Windows
Installing Django for Linux
Installing Django for Mac OS
Starting your project with Django
Creating an application
Configuring the application
Summary
3. Hello World! with Django
Routing in Django
Regular expressions
The uninterpreted characters
The beginning and the end of the line
The any character regular expression
Character classes
Validating the number of characters
Creating our first URL
Creating our first view
Testing our application
Summary
4. Working with Templates
Displaying Hello world! in a template
Injecting the data from the view to the template
Creating dynamic templates
Integrating variables in templates
Conditional statements
Looping in a template
Using filters
The upper and lower filters
The lower filter
The upper filter
The capfirst filter
The pluralize filter
The escape and safe to avoid XSS filters
The linebreaks filter
The truncatechars filter
Creating DRY URLs
Extending the templates
Using static files in templates
Summary
5. Working with Models
Databases and Django
Migrations with South
Installing South
Using the South extension
Creating simple models
The UserProfile model
The Project model
The relationship between the models
Creating the task model with relationships
Extending models
The admin module
Installing the module
Using the module
Advanced usage of models
Using two relationships for the same model
Defining the str method
Summary
6. Getting a Model's Data with Querysets
The persisting model's data on the database
Filling a model and saving it in the database
Getting data from the database
Getting multiple records
Getting only one record
Getting a model instance from the queryset instance
Using the get parameter
Saving the foreign key
Updating records in the database
Updating a model instance
Updating multiple records
Deleting a record
Getting linked records
Advanced usage of the queryset
Using an OR operator in a queryset
Using the lower and greater than lookups
Performing an exclude query
Making a raw SQL query
Summary
7. Working with Django Forms
Adding a developer without using Django forms
Template of an HTML form
The view using the POST data reception
Adding a developer with Django forms
CSRF protection
The view with a Django form
Template of a Django form
The form based on a model
The supervisor creation form
Advanced usage of Django forms
Extending the validation form
Customizing the display of errors
Using widgets
Setting initial data in a form
When instantiating the form
When defining fields
Summary
8. Raising Your Productivity with CBV
The CreateView CBV
An example of minimalist usage
Working with ListView
An example of minimalist usage
Extending ListView
The DetailView CBV
An example of minimalist usage
Extending DetailView
The UpdateView CBV
An example of minimalist usage
Extending the UpdateView CBV
The DeleteView CBV
Going further by extending the CBV
Using a custom class CBV update
Summary
9. Using Sessions
Creating and getting session variables
An example – showing the last task consulted
About session security
Summary
10. The Authentication Module
How to use the authentication module
Configuring the Django application
Editing the UserProfile model
Adding a user
Login and logout pages
Restricting access to the connected members
Restricting access to views
Restricting access to URLs
Summary
11. Using AJAX with Django
Working with jQuery
jQuery basics
CSS selectors in jQuery
Getting back the HTML content
Setting HTML content in an element
Looping elements
Importing the jQuery library
Working with AJAX in the task manager
Summary
12. Production with Django
Completing the development
Selecting the physical server
Selecting the server software
Selecting the server database
Deploying the Django website
Installing PIP and Python 3
Installing PostgreSQL
Installing virtualenv and creating a virtual environment
Installing Django, South, Gunicorn, and psycopg2
Configuring PostgreSQL
Adaptation of Work_manager to production
Initial South migration
Using Gunicorn
Starting Nginx
Summary
A. Cheatsheet
The field types in models
The numerical field type
The string field type
The temporal field type
Other types of fields
Relationship between models
The model meta attributes
Options common to all fields of models
The form fields
Common options for the form fields
The widget form
Error messages (forms and models)
The template language
Template tags
Loops in dictionaries
Conditional statements
The template filters
The queryset methods
2. Module 2
1. Getting Started with Django 1.8
Introduction
Working with a virtual environment
Getting ready
How to do it…
How it works…
See also
Creating a project file structure
Getting ready
How to do it…
How it works…
See also
Handling project dependencies with pip
Getting ready
How to do it…
How it works…
There's more…
See also
Making your code compatible with both Python 2.7 and Python 3
Getting ready
How to do it…
How it works…
Including external dependencies in your project
Getting ready
How to do it…
How it works…
See also
Configuring settings for development, testing, staging, and production environments
Getting ready
How to do it…
How it works…
See also
Defining relative paths in the settings
Getting ready
How to do it…
How it works…
See also
Creating and including local settings
Getting ready
How to do it…
How it works…
See also
Setting up STATIC_URL dynamically for Subversion users
Getting ready
How to do it…
How it works…
See also
Setting up STATIC_URL dynamically for Git users
Getting ready
How to do it…
How it works…
See also
Setting UTF-8 as the default encoding for MySQL configuration
Getting ready
How to do it…
How it works…
Setting the Subversion ignore property
Getting ready
How to do it…
How it works…
See also
Creating the Git ignore file
Getting ready
How to do it…
How it works…
See also
Deleting Python-compiled files
Getting ready
How to do it…
How it works…
See also
Respecting the import order in Python files
Getting ready
How to do it…
How it works…
There's more…
See also
Creating app configuration
Getting ready
How to do it…
How it works…
There is more…
See also
Defining overwritable app settings
Getting ready
How to do it…
How it works…
2. Database Structure
Introduction
Using model mixins
Getting ready
How to do it…
How it works…
There's more…
See also
Creating a model mixin with URL-related methods
Getting ready
How to do it…
How it works…
See also
Creating a model mixin to handle creation and modification dates
Getting ready
How to do it…
How it works…
See also
Creating a model mixin to take care of meta tags
Getting ready
How to do it…
How it works…
See also
Creating a model mixin to handle generic relations
Getting ready
How to do it…
How it works…
See also
Handling multilingual fields
Getting ready
How to do it…
How it works…
Using migrations
Getting ready
How to do it…
How it works…
See also
Switching from South migrations to Django migrations
Getting ready
How to do it…
How it works…
See also
Changing a foreign key to the many-to-many field
Getting ready
How to do it…
How it works…
See also
3. Forms and Views
Introduction
Passing HttpRequest to the form
Getting ready
How to do it…
How it works…
See also
Utilizing the save method of the form
Getting ready
How to do it…
How it works…
See also
Uploading images
Getting ready
How to do it…
How it works…
There's more
See also
Creating a form layout with django-crispy-forms
Getting ready
How to do it…
How it works…
There's more…
See also
Downloading authorized files
Getting ready
How to do it…
How it works…
See also
Filtering object lists
Getting ready
How to do it…
How it works…
See also
Managing paginated lists
Getting ready
How to do it…
How it works…
See also
Composing class-based views
Getting ready
How to do it…
How it works…
There's more…
See also
Generating PDF documents
Getting ready
How to do it…
How it works…
See also
Implementing a multilingual search with Haystack
Getting ready
How to do it…
How it works…
See also
4. Templates and JavaScript
Introduction
Arranging the base.html template
Getting ready
How to do it…
How it works…
See also
Including JavaScript settings
Getting ready
How to do it…
How it works…
See also
Using HTML5 data attributes
Getting ready
How to do it…
How it works…
See also
Opening object details in a modal dialog
Getting ready
How to do it…
How it works…
See also
Implementing a continuous scroll
Getting ready
How to do it…
How it works…
See also
Implementing the Like widget
Getting ready
How to do it…
How it works…
See also
Uploading images by Ajax
Getting ready
How to do it…
How it works…
See also
5. Custom Template Filters and Tags
Introduction
Following conventions for your own template filters and tags
How to do it...
Creating a template filter to show how many days have passed since a post was published
Getting ready
How to do it...
How it works...
There's more...
See also
Creating a template filter to extract the first media object
Getting ready
How to do it...
How it works...
There's more...
See also
Creating a template filter to humanize URLs
Getting ready
How to do it...
How it works...
See also
Creating a template tag to include a template if it exists
Getting ready
How to do it...
How it works...
There's more...
See also
Creating a template tag to load a QuerySet in a template
Getting ready
How to do it...
How it works...
See also
Creating a template tag to parse content as a template
Getting ready
How to do it...
How it works...
See also
Creating a template tag to modify request query parameters
Getting ready
How to do it...
How it works...
See also
6. Model Administration
Introduction
Customizing columns on the change list page
Getting ready
How to do it...
How it works...
There's more...
See also
Creating admin actions
Getting ready
How to do it...
How it works...
See also
Developing change list filters
Getting ready
How to do it...
How it works...
See also
Customizing default admin settings
Getting ready
How to do it...
How it works...
There's more...
See also
Inserting a map into a change form
Getting ready
How to do it...
How it works...
See also
7. Django CMS
Introduction
Creating templates for Django CMS
Getting ready
How to do it...
How it works...
See also
Structuring the page menu
Getting ready
How to do it...
How it works...
See also
Converting an app to a CMS app
Getting ready
How to do it...
How it works...
See also
Attaching your own navigation
Getting ready
How to do it...
How it works...
See also
Writing your own CMS plugin
Getting ready
How to do it...
How it works...
See also
Adding new fields to the CMS page
Getting ready
How to do it...
How it works...
See also
8. Hierarchical Structures
Introduction
Creating hierarchical categories
Getting ready
How to do it...
How it works...
See also
Creating a category administration interface with django-mptt-admin
Getting ready
How to do it...
How it works...
See also
Creating a category administration interface with django-mptt-tree-editor
Getting ready
How to do it...
How it works...
See also
Rendering categories in a template
Getting ready
How to do it...
How it works...
There's more...
See also
Using a single selection field to choose a category in forms
Getting ready
How to do it...
How it works...
See also
Using a checkbox list to choose multiple categories in forms
Getting ready
How to do it...
How it works...
See also
9. Data Import and Export
Introduction
Importing data from a local CSV file
Getting ready
How to do it...
How it works...
There's more...
See also
Importing data from a local Excel file
Getting ready
How to do it...
How it works...
There's more...
See also
Importing data from an external JSON file
Getting ready
How to do it...
How it works...
See also
Importing data from an external XML file
Getting ready
How to do it...
How it works...
There's more...
See also
Creating filterable RSS feeds
Getting ready
How to do it...
How it works...
See also
Using Tastypie to create API
Getting ready
How to do it...
How it works...
See also
Using Django REST framework to create API
Getting ready
How to do it...
How it works...
See also
10. Bells and Whistles
Introduction
Using the Django shell
Getting ready
How to do it...
How it works...
See also
Using database query expressions
Getting ready
How to do it...
How it works...
See also
Monkey-patching the slugify() function for better internationalization support
Getting ready
How to do it...
How it works...
There's more...
See also
Toggling the Debug Toolbar
Getting ready
How to do it...
How it works...
See also
Using ThreadLocalMiddleware
Getting ready
How to do it...
How it works...
See also
Caching the method return value
Getting ready
How to do it...
How it works...
See also
Using Memcached to cache Django views
Getting ready
How to do it...
How it works...
See also
Using signals to notify administrators about new entries
Getting ready
How to do it...
How it works...
See also
Checking for missing settings
Getting ready
How to do it...
How it works...
See also
11. Testing and Deployment
Introduction
Testing pages with Selenium
Getting ready
How to do it...
How it works...
See also
Testing views with mock
Getting ready
How to do it...
How it works...
See also
Testing API created using Django REST framework
Getting ready
How to do it...
How it works...
See also
Releasing a reusable Django app
Getting ready
How to do it...
How it works...
See also
Getting detailed error reporting via e-mail
Getting ready
How to do it...
How it works...
See also
Deploying on Apache with mod_wsgi
Getting ready
How to do it...
How it works...
There's more...
See also
Setting up cron jobs for regular tasks
Getting ready
How to do it...
How it works...
See also
Creating and using the Fabric deployment script
Getting ready
How to do it...
How it works...
There's more...
See also
3. Module 3
1. Django and Patterns
How does Django work to?
What is a Pattern?
Gang of Four Patterns
Is Django MVC?
Fowler's Patterns
Are there more patterns?
Patterns in this book
Criticism of Patterns
How to use Patterns
Best practices
Python Zen and Django's design philosophy
Summary
2. Application Design
How to gather requirements
Are you a story teller?
HTML mockups
Designing the application
Dividing a project into Apps
Reuse or roll-your-own?
My app sandbox
Which packages made it?
Before starting the project
SuperBook – your mission, should you choose to accept it
Why Python 3?
Starting the project
Summary
3. Models
M is bigger than V and C
The model hunt
Splitting models.py into multiple files
Structural patterns
Patterns – normalized models
Problem details
Solution details
Three steps of normalization
First normal form (1NF)
Second normal form or 2NF
Third normal form or 3NF
Django models
Performance and denormalization
Should we always normalize?
Pattern – model mixins
Problem details
Solution details
Model mixins
Pattern – user profiles
Problem details
Solution details
Signals
Admin
Multiple profile types
Pattern – service objects
Problem details
Solution details
Retrieval patterns
Pattern – property field
Problem details
Solution details
Cached properties
Pattern – custom model managers
Problem details
Solution details
Set operations on QuerySets
Chaining multiple QuerySets
Migrations
Summary
4. Views and URLs
A view from the top
Views got classier
Class-based generic views
View mixins
Order of mixins
Decorators
View patterns
Pattern – access controlled views
Problem details
Solution details
Pattern – context enhancers
Problem details
Solution details
Pattern – services
Problem details
Solution details
Designing URLs
URL anatomy
What happens in urls.py?
The URL pattern syntax
Mnemonic – parents question pink action-figures
Names and namespaces
Pattern order
URL pattern styles
Departmental store URLs
RESTful URLs
Summary
5. Templates
Understanding Django's template language features
Variables
Attributes
Filters
Tags
Philosophy – don't invent a programming language
Organizing templates
Support for other template languages
Using Bootstrap
But they all look the same!
Template patterns
Pattern – template inheritance tree
Problem details
Solution details
Pattern – the active link
Problem details
Solution details
A template-only solution
Custom tags
Summary
6. Admin Interface
Using the admin interface
Enhancing models for the admin
Not everyone should be an admin
Admin interface customizations
Changing the heading
Changing the base and stylesheets
Adding a Rich Text Editor for WYSIWYG editing
Bootstrap-themed admin
Complete overhauls
Protecting the admin
Pattern – feature flags
Problem details
Solution details
Summary
7. Forms
How forms work
Forms in Django
Why does data need cleaning?
Displaying forms
Time to be crisp
Understanding CSRF
Form processing with Class-based views
Form patterns
Pattern – dynamic form generation
Problem details
Solution details
Pattern – user-based forms
Problem details
Solution details
Pattern – multiple form actions per view
Problem details
Solution details
Separate views for separate actions
Same view for separate actions
Pattern – CRUD views
Problem details
Solution details
Summary
8. Dealing with Legacy Code
Finding the Django version
Activating the virtual environment
Where are the files? This is not PHP
Starting with urls.py
Jumping around the code
Understanding the code base
Creating the big picture
Incremental change or a full rewrite?
Write tests before making any changes
Step-by-step process to writing tests
Legacy databases
Summary
9. Testing and Debugging
Why write tests?
Test-driven development
Writing a test case
The assert method
Writing better test cases
Mocking
Pattern – test fixtures and factories
Problem details
Solution details
Learning more about testing
Debugging
Django debug page
A better debug page
The print function
Logging
The Django Debug Toolbar
The Python debugger pdb
Other debuggers
Debugging Django templates
Summary
10. Security
Cross-site scripting (XSS)
Why are your cookies valuable?
How Django helps
Where Django might not help
Cross-Site Request Forgery (CSRF)
How Django helps
Where Django might not help
SQL injection
How Django helps
Where Django might not help
Clickjacking
How Django helps
Shell injection
How Django helps
And the list goes on
A handy security checklist
Summary
11. Production-ready
Production environment
Choosing a web stack
Components of a stack
Hosting
Platform as a service
Virtual private servers
Other hosting approaches
Deployment tools
Fabric
Typical deployment steps
Configuration management
Monitoring
Performance
Frontend performance
Backend performance
Templates
Database
Caching
Cached session backend
Caching frameworks
Caching patterns
Summary
A. Python 2 versus Python 3
But I still use Python 2.7!
Python 3
Python 3 for Djangonauts
Change all the __unicode__ methods into __str__
All classes inherit from the object class
Calling super() is easier
Relative imports must be explicit
HttpRequest and HttpResponse have str and bytes types
Exception syntax changes and improvements
Standard library reorganized
New goodies
Using Pyvenv and Pip
Other changes
Further information
A. Bibliography
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜