Home Page Icon
Home Page
Table of Contents for
Further information
Close
Further information
by Arun Ravindran
Django Design Patterns and Best Practices
Django Design Patterns and Best Practices
Table of Contents
Django Design Patterns and Best Practices
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Django and Patterns
Why Django?
The story of Django
A framework is born
Removing the magic
Django keeps getting better
How does Django work?
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
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
Summary
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
Migrations
Summary
4. Views and URLs
A view from the top
Views got classier
Class-based generic views
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
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
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 Python debugger pdb
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
Index
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
Python 3
Next
Next Chapter
Index
Further information
Read
What's New In Python 3.0
by
Guido at
https://docs.python.org/3/whatsnew/3.0.html
To find what is new in each release of Python, read
What's New in Python
at
https://docs.python.org/3/whatsnew/
For richly detailed answers about Python 3 read
Python 3 Q & A
by Nick Coghlan at
http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html
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