Django Design Patterns and Best Practices
eBook - ePub

Django Design Patterns and Best Practices

Arun Ravindran

Partager le livre
  1. 222 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Django Design Patterns and Best Practices

Arun Ravindran

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Django Design Patterns and Best Practices est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Django Design Patterns and Best Practices par Arun Ravindran en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Web Development. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2015
ISBN
9781783986644

Django Design Patterns and Best Practices


Table of Contents

Django Design Patterns and Best Practices
Credits
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
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 reor...

Table des matiĂšres