Lightweight Django_ Using REST, Websockets & Backbone [Elman & Lavin 2014-11-13].pdf

(4069 KB) Pobierz
Django
USING REST, WEBSOCKETS & BACKBONE
Lightweight
Julia Elman & Mark Lavin
Lightweight Django
How can you take advantage of the Django framework to integrate complex
client-side interactions and real-time features into your web applications?
Through a series of rapid application development projects, this hands-on
book shows experienced Django developers how to include REST APIs,
WebSockets, and client-side MVC frameworks such as Backbone.js into
new or existing projects.
Learn how to make the most of Django’s decoupled design by choosing
the components you need to build the lightweight applications you want.
Once you finish this book, you’ll know how to build single-page applications
that respond to interactions in real time. If you’re familiar with Python and
JavaScript, you’re good to go.
A great resource for
going beyond traditional
apps and learning how
Django can power the
backend of single-page
web applications.
Django core developer, CTO, oscaro.com
—Aymeric Augustin
Learn a lightweight approach for starting a new Django project
Break reusable applications into smaller services that
communicate with one another
Create a static, rapid prototyping site as a scaffold for websites
and applications
Build a REST API with django-rest-framework
Learn how to use Django with the Backbone.js MVC framework
Create a single-page web application on top of your REST API
Integrate real-time features with WebSockets and the Tornado
networking library
Use the book’s code-driven examples in your own projects
Such a good idea—I think
this will lower the barrier
of entry for developers
even more… the more
I read, the more excited
I am!
Python Developer, Cox Media Group
—Barbara Shaurette
Julia Elman,
a frontend developer and tech education advocate, started learning
Django in 2008 while working at World Online. She is one of the co-founders for
Girl Develop It RDU and PyLadies RDU, organizations that have helped over 850
women learn to program.
Mark Lavin
is Technical Director at Caktus Consulting Group in Durham, North
Carolina. He came to Python web development after years of pricing derivatives
on Wall Street. Mark maintains several open source projects related to Django
development.
PY THON/ WEB DEVELOPMENT
Twitter: @oreillymedia
facebook.com/oreilly
US $39.99
CAN $41.99
ISBN: 978-1-491-94594-0
Lightweight Django
Julia Elman and Mark Lavin
Lightweight Django
by Julia Elman and Mark Lavin
Copyright © 2015 Julia Elman and Mark Lavin. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editor:
Meghan Blanchette
Production Editor:
Colleen Lobner
Copyeditor:
Rachel Monaghan
Proofreader:
Sonia Saruba
November 2014:
First Edition
Indexer:
Wendy Catalano
Cover Designer:
Ellie Volckhausen
Interior Designer:
David Futato
Illustrator:
Rebecca Demarest
Revision History for the First Edition:
2014-10-24:
First release
See
http://oreilly.com/catalog/errata.csp?isbn=9781491945940
for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Lightweight Django,
the cover image, and
related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark
claim, the designations have been printed in caps or initial caps.
While the publisher and the authors have used good faith efforts to ensure that the information and in‐
structions contained in this work are accurate, the publisher and the authors disclaim all responsibility for
errors or omissions, including without limitation responsibility for damages resulting from the use of or
reliance on this work. Use of the information and instructions contained in this work is at your own risk. If
any code samples or other technology this work contains or describes is subject to open source licenses or
the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies
with such licenses and/or rights.
ISBN: 978-1-491-94594-0
LSI
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Prerequisites. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
1. The World’s Smallest Django Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Hello Django
Creating the View
The URL Patterns
The Settings
Running the Example
Improvements
WSGI Application
Additional Configuration
Reusable Template
1
2
2
3
4
5
6
7
10
2. Stateless Web Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Why Stateless?
Reusable Apps Versus Composable Services
Placeholder Image Server
Views
URL Patterns
Placeholder View
Image Manipulation
Adding Caching
Creating the Home Page View
Adding Static and Template Settings
Home Page Template and CSS
Completed Project
13
14
14
16
16
17
18
20
23
23
24
26
iii
Zgłoś jeśli naruszono regulamin