Lightweight_Django.pdf.pdf

所需积分/C币:9 2019-09-15 00:23:59 4.07MB PDF
收藏 收藏
举报

Lightweight_Django.pdf
Lightweight Django Julia elman and mark lavin Beijing. Cambridge. Farnham·kin· Sebastopol. okyo OREILLY Lightweight django by julia Elman and mark lavin Copyright o 2015 Julia Elman and Mark Lavin. All rights reserved Printed in the United States of America Published by oreilly 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 Isoavailableformosttitles(http://safaribooksonline.com).Formoreinformationcontactourcorporate institutionalsalesdepartment800-998-9938orcorporate@oreilly.com Editor: Meghan Blanchette Indexer: Wendy catalano Production Editor: Colleen Lobner Cover Designer: Ellie Volckhausen Copyeditor: Rachel Monaghan Interior Designer: David Futato Proofreader: Sonia aruba llustrator: rebecca demarest Noⅴ ember20l4 First edition Revision History for the First Edition 2014-10-24 First release Seehttp://oreilly.com/catalog/errata.cspisbn=9781491945940forreleasedetails The Oreilly logo is a registered trademark of 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 a trademarks. Where those designations appear in this book, and O Reilly Media, Inc was aware ofa 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-49194594-0 Table of contents Preface Prerequisite 1. The World s Smallest Django Project Hello django Creating the vier The url Patterns The setti gs Running the example Improvements WSGI Application 12234567 Additional Configuration Reusable template 2. Stateless Web application 13 Why Stateless? 13 Reusable apps Versus Composable Services Placeholder Image Server Ⅴiews 4466 URL Patterns Placeholder view Image manipulation 18 Adding Caching 20 Creating the Home Page View 23 Adding Static and Template Settings 23 Home Page Template and Css 24 Completed Proje 26 3. Building a Static Site Generator 31 Creating Static Sites with Django 31 What Is Rapid Prototyping Initial Project Layout 32 File/ Folder Scaffolding 32 Basic Settings 33 Page rendering 35 Creating Our Base Templates 35 Static Page Generator 36 Basic Styling 39 Prototype layouts and navigation 41 Generating static Content 46 Settings Configuration 46 Custom Management Command Building a single page Serving and Compressing Static Files 50 Hashing our css and javaScript files 50 Compressing Our Static Files 51 enerating dynamic content 54 Updating Our Templates 54 Adding Metadata 56 4. Building a REST APL. Django and rest 61 Scrum Board Data Map 62 Initial Project layout Project Settings 64 No Diango admin? Models 6 Designing the aPI 69 Sprint endpoints Task and User Endpoints 71 Connecting to the Router 74 Linking resources Testing Out the aPi USing the Browsable API 77 Adding Filtering 81 Adding Validations 86 Using a Python Client 89 Next Steps 91 iv Table of Contents 5. Client-Side Django with Backbone. js Brief Overview of backbone 94 Setting Up Your Project Files JavaScript Dependencies 96 Organization of Your Backbone application Files 98 Connecting Backbone to Django 100 Client-Side backbone routing 102 Creating a basic Home page view 102 Setting Up a Minimal router 103 Using_ template from Underscore. js 104 Building User Authentication 107 Creating a Session Model 107 Creating a Login View Generic FormⅤiew 117 Authenticating routes Creating a Header view 121 6. Single-Page Web application 131 What Are Single-Page Web Applications? 131 Discovering the api 132 Fetching the API 132 Model customizations 133 Collection Customizations 134 Building Our Home Page 135 Displaying the Current Sprints 135 Creating New Sprints 138 Sprint Detail Page 141 Rendering the Sprint 141 Routi the sprint detail Using the Client State 144 Rendering the Tasks 146 AddTaskview 153 CRUD Ta 156 Rendering Tasks Within a Sprint 156 Updating tasks 160 Inline edit Features 163 7. Real-Time Django 167 HTML5 Real-Time APis 167 Websockets 168 Server-Sent events 168 Webrtc 169 Table of Contents I Websockets with tornado 169 Introduction to tornado 170 sSage Subscriptio 175 Client Communication 178 Minimal example 179 182 Client Connection 185 Sending events from the client 187 Handling events from the client 193 Updating Task State 195 8. Communication Between Django and tornado 春。鲁 99 Receiving updates in Tornado 199 Sendi U ing Up dates from di 201 Handling updates on the client 203 Server lmprovements 204 Robust subscriptions 204 Websocket Authentication 208 Better Up alates 212 Secure update 214 Final websocket server 217 Index 223 Table of contents Preface Since the creation of Django, a plethora of web frameworks have been created in various open source communities. Frontend-focused web frameworks such as Angular. js, Em- ber. js, and Backbone. js have come out of the JavaScript community and become fore- runners in modern web development. Where does Django fit into all of this? How can we integrate these client-side mvc frameworks into our current Django infrastructure? Lightweight Diango teaches you how to take advantage of Django's Pythonic"batteries ncludedphilosophy. Its aim is to guide you through misconceptions that Django is too heavy" for rapid application development. From creating the world's smallest Django application to building a RESTful API, Lightweight Django will walk you through how to take advantage of this popular Python web framework Why This Book? We wanted to write this book primarily because we love Django. The community is amazing, and there are so many resources to learn about Django and to develop appli cations using it. However, we also felt like many of these resources, including the official Django documentation, put too much emphasis on the power of django and not on its decoupled design. Django is a well-written framework, with numerous utilities for building web applications included. What we want this book to highlight is how you can break apart and potentially replace these components to pick and choose what best suits the application you want to build. Similarly, we wanted to break down the typical structure of Django projects and applications. Our goal is to get you to stop asking"how do i do X in django? and instead ask does Django provide anything to help me do X, and if not, is something available in the community? In addition, we wanted to answer questions about where Django fits in a Web in which more applications are built with heavy client-side interactions and real-time compo nents,and paired with native mobile applications. As a framework, Django is agnostic bout the client, which leaves some users feeling like Django doesnt have an answer for building these types of applications. We hope that this book can help shape how the community approaches these types of problems. We want to see Django and its com munity continue to grow, and we want to be a part of it for many more years to come Who should read this book? If you are interested in reading this book, you are most likely an intermediate Django user. You've gone through the Django polls tutorial, as well as written a few basic Django web applications, and are now wondering what the next steps are Lightweight Django serves as that next step to help outline how to utilize Django's utilities and simplicity. Or you might be currently working on a django project and wondering how to integrate something like Backbone. js into your project Lightweight diango will teach you some best practices for integration and will give you a jumping-off point for building content rich web applications Who should not read this book? While we feel that Lightweight Django is beneficial to developers from many back- grounds, there might be certain people who wont find this book interesting. For those of you who do not find writing Python and/or JavaScript pleasurable, this book is most likely not for you. All of the concepts and examples revolve around these languages, and they will be heavily used throughout each chapter. We also don' t recommend this book for those who are brand new to django About the examples Each of the example projects has been carefully crafted under the theme of rapid ap plication development. In each chapter, you'll learn how to build projects that assist with project management, tools, and team collaboration. We wanted our readers to build projects that they find useful and can customize for their own use. In general, if example code is offered with this book you may use it in your programs and documentation You do not need to contact us for permission unless you' re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of ex- amples from O Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a sig nificant amount of example code from this book into your products documentation does require permission Thecodesamplesforthistitlecanbefoundhere:https://github.com/lightweightdjango/ exan pi I Preface

...展开详情
试读 245P Lightweight_Django.pdf.pdf
立即下载 低至0.43元/次 身份认证VIP会员低至7折
抢沙发
一个资源只可评论一次,评论内容不能少于5个字
weixin_38744270 你的留言是对我莫大的支持
2019-09-15
  • 至尊王者

    成功上传501个资源即可获取
关注 私信 TA的资源
上传资源赚积分or赚钱
最新推荐
Lightweight_Django.pdf.pdf 9积分/C币 立即下载
1/245
Lightweight_Django.pdf.pdf第1页
Lightweight_Django.pdf.pdf第2页
Lightweight_Django.pdf.pdf第3页
Lightweight_Django.pdf.pdf第4页
Lightweight_Django.pdf.pdf第5页
Lightweight_Django.pdf.pdf第6页
Lightweight_Django.pdf.pdf第7页
Lightweight_Django.pdf.pdf第8页
Lightweight_Django.pdf.pdf第9页
Lightweight_Django.pdf.pdf第10页
Lightweight_Django.pdf.pdf第11页
Lightweight_Django.pdf.pdf第12页
Lightweight_Django.pdf.pdf第13页
Lightweight_Django.pdf.pdf第14页
Lightweight_Django.pdf.pdf第15页
Lightweight_Django.pdf.pdf第16页
Lightweight_Django.pdf.pdf第17页
Lightweight_Django.pdf.pdf第18页
Lightweight_Django.pdf.pdf第19页
Lightweight_Django.pdf.pdf第20页

试读结束, 可继续阅读

9积分/C币 立即下载 >