100% found this document useful (1 vote)
10 views

Practical Django Projects Second Edition James Bennettinstant download

The document provides links to download various ebooks and textbooks, including 'Practical Django Projects, Second Edition' by James Bennett, which focuses on using Django for web development. It highlights the book's aim to simplify web development and improve coding efficiency through practical projects. Additionally, it mentions other related titles available for download on the same platform.

Uploaded by

ackelabnb
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
10 views

Practical Django Projects Second Edition James Bennettinstant download

The document provides links to download various ebooks and textbooks, including 'Practical Django Projects, Second Edition' by James Bennett, which focuses on using Django for web development. It highlights the book's aim to simplify web development and improve coding efficiency through practical projects. Additionally, it mentions other related titles available for download on the same platform.

Uploaded by

ackelabnb
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download the full version and explore a variety of ebooks

or textbooks at https://ebookultra.com

Practical Django Projects Second Edition James


Bennett

_____ Tap the link below to start your download _____

https://ebookultra.com/download/practical-django-projects-
second-edition-james-bennett/

Find ebooks or textbooks at ebookultra.com today!


We have selected some products that you may be interested in
Click the link to download now or visit ebookultra.com
for more options!.

Practical JBoss Seam Projects 1st Edition Jim Farley

https://ebookultra.com/download/practical-jboss-seam-projects-1st-
edition-jim-farley/

Django for APIs Build web APIs with Python and Django
William S Vincent

https://ebookultra.com/download/django-for-apis-build-web-apis-with-
python-and-django-william-s-vincent/

Two Scoops of Django Best Practices For Django 1 5 1st


Edition Daniel Greenfeld

https://ebookultra.com/download/two-scoops-of-django-best-practices-
for-django-1-5-1st-edition-daniel-greenfeld/

Practical Computer Analysis of Switch Mode Power Supplies


1st Edition Johnny C. Bennett

https://ebookultra.com/download/practical-computer-analysis-of-switch-
mode-power-supplies-1st-edition-johnny-c-bennett/
Cardiac Arrhythmias Practical Notes on Interpretation and
Treatment 7th Edition David H. Bennett

https://ebookultra.com/download/cardiac-arrhythmias-practical-notes-
on-interpretation-and-treatment-7th-edition-david-h-bennett/

Practical REST on Rails 2 Projects 1st Edition Ben


Scofield

https://ebookultra.com/download/practical-rest-on-
rails-2-projects-1st-edition-ben-scofield/

Pro Django 2nd Edition Marty Alchin

https://ebookultra.com/download/pro-django-2nd-edition-marty-alchin/

Media Independence Working with Freedom or Working for


Free 1st Edition James Bennett

https://ebookultra.com/download/media-independence-working-with-
freedom-or-working-for-free-1st-edition-james-bennett/

Oxford Guide to Behavioural Experiments in Cognitive


Therapy 1st Edition James Bennett-Levy

https://ebookultra.com/download/oxford-guide-to-behavioural-
experiments-in-cognitive-therapy-1st-edition-james-bennett-levy/
Practical Django Projects Second Edition James Bennett
Digital Instant Download
Author(s): James Bennett
ISBN(s): 9781430219392, 1430219394
File Details: PDF, 5.10 MB
Year: 2009
Language: english
 CYAN  YELLOW
 MAGENTA BLACK
 PANTONE 123 C

Books for professionals by professionals ® The EXPERT’s VOIce ® in Web Development


Companion
eBook
Available
Updated for
Practical Django Projects, Second Edition
Django 1.1

Practical Django Projects


Dear Reader,

Practical
Web development should be fun and easy, with a minimum of fuss.
Unfortunately, sometimes it feels as though web development is nothing but
fuss. Even the simplest applications involve a staggering amount of repetitive
busy work that drags the whole process down. In this book, you’ll learn how
Django—a Python-based, open source web-application framework developed
by a fast-paced online news operation—can take the burden of all that tedium
off your shoulders and help you write better web applications with less code.
The aim of this book is to guide you toward becoming a more effective pro-
grammer, regardless of whether you’re a novice web developer or a seasoned
veteran. This book explains the technical details of developing applications
with Django, but more important, it shows you how Django can help you write
clean, flexible code with an eye toward reusability.
The book is organized around three useful projects: a content management
system, a weblog application, and a social code-sharing site. The process of
building each one will expand your knowledge of Django and demonstrate best

Projects
practices for developing high-quality applications. As you progress through
these projects, you’ll come to understand each of Django’s major components,
from database interaction and server-side processing all the way up to form
handling for user interaction and HTML templating for presentation. Along the
way, you’ll also learn how Django’s application architecture can lead to pow-
erful and flexible applications that you’ll be able to use and reuse whenever
you need them. You’ll pick up key principles of application design that you can
apply to your own code.
Finally, this updated and expanded edition will introduce you to several
powerful new features of Django, including Django’s newly rewritten adminis-
trative interface and commenting system. Plus, it includes an all-new chapter Write better web applications faster, and learn
covering practical development tools and techniques that you can incorporate
into your own development workflow.
how to build up your own reusable code library
Companion eBook James Bennett

Second
Edition
THE APRESS ROADMAP
See last page for details
Practical Django Projects,
Second Edition
Second Edition
on $10 eBook version Beginning Python, Pro Django
Second Edition
The Definitive Guide to
Django, Second Edition

SOURCE CODE ONLINE


www.apress.com ISBN 978-1-4302-1938-5
Bennett James Bennett
54499
Django Release Manager
US $44.99

Shelve in
Web development

User level: 9 781430 219385


Beginner–Intermediate

this print for content only—size & color not accurate spine = 0.633" 272 page count
Practical Django Projects
Second Edition

James Bennett
Practical Django Projects, Second Edition
Copyright © 2009 by James Bennett
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-4302-1938-5
ISBN-13 (electronic): 978-1-4302-1939-2
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the
United States and other countries.
Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written without endorsement
from Sun Microsystems, Inc.
Lead Editor: Duncan Parkes
Technical Reviewer: Ben Ford
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell,
Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper,
Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Senior Project Manager: Kylie Johnston
Copy Editor: Nina Goldschlager Perry
Associate Production Director: Kari Brooks-Copony
Senior Production Editor: Laura Cheu
Compositor: Lynn L’Heureux
Proofreader: BIM Indexing & Proofreading Services
Indexer: Ron Strauss
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com,
or visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600,
Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://
www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.
eBook versions and licenses are also available for most titles. For more information, reference our Special
Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every precau-
tion has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability
to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indi-
rectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com.
Contents at a Glance

About the Author. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi


About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Chapter 1 Welcome to Django . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


Chapter 2 Your First Django Site: A Simple CMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Chapter 3 Customizing the Simple CMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Chapter 4 A Django-Powered Weblog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Chapter 5 Expanding the Weblog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Chapter 6 Templates for the Weblog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Chapter 7 Finishing the Weblog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Chapter 8 A Social Code-Sharing Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Chapter 9 Form Processing in the Code-Sharing Application. . . . . . . . . . . . . . . 165
Chapter 10 Finishing the Code-Sharing Application. . . . . . . . . . . . . . . . . . . . . . . . . 187
CHAPTER 11 Practical Development Techniques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Chapter 12 Writing Reusable Django Applications. . . . . . . . . . . . . . . . . . . . . . . . . . 223

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

iii
Contents

About the Author. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi


About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Chapter 1 Welcome to Django . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

What’s a Web Framework and Why Should I Want One?. . . . . . . . . . . . . . . 1


Saying Hello to Django . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Saying Hello to Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Installing Django . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Taking Your First Steps with Django . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Exploring Your Django Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Chapter 2 Your First Django Site: A Simple CMS . . . . . . . . . . . . . . . . . . . . . . 9

Configuring Your First Django Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9


Putting Together the CMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Introducing the Django Template System. . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Chapter 3 Customizing the Simple CMS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Adding Rich-Text Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23


Adding a Search System to the CMS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Improving the Search View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Improving the Search Function with Keywords . . . . . . . . . . . . . . . . . . . . . . 33
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

v
vi ■CO NTENT S

Chapter 4 A Django-Powered Weblog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Compiling a Feature Checklist. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43


Writing a Django Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Projects vs. Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Standalone and Coupled Applications . . . . . . . . . . . . . . . . . . . . . . . . . 45
Creating the Weblog Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Designing the Models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Building the Entry Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Basic Fields. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Slugs, Useful Defaults, and Uniqueness Constraints. . . . . . . . . . . . . 54
Authors, Comments, and Featured Entries . . . . . . . . . . . . . . . . . . . . . 55
Different Types of Entries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Categorizing and Tagging Entries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Writing Entries Without Writing HTML . . . . . . . . . . . . . . . . . . . . . . . . . 60
Finishing Touches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
The Weblog Models So Far . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Writing the First Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Using Django’s Generic Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Decoupling the URLs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

Chapter 5 Expanding the Weblog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

Writing the Link Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77


Views for the Link Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Setting Up Views for Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Using Generic Views (Again) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Views for Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Cleaning Up the URLConf Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Handling Live Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
■C O N T E N T S vii

Chapter 6 Templates for the Weblog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

Dealing with Repetitive Elements: The Power of Inheritance. . . . . . . . . . . 97


How Template Inheritance Works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Limits of Template Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Defining the Base Template for the Blog. . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Setting Up Section Templates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Displaying Archives of Entries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Entry Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Yearly Archive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Monthly and Daily Archives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Entry Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Defining Templates for Other Types of Content. . . . . . . . . . . . . . . . . . . . . 110
Extending the Template System with Custom Tags . . . . . . . . . . . . . . . . . 111
How a Django Template Works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
A Simple Custom Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Writing a More Flexible Tag with Arguments . . . . . . . . . . . . . . . . . . 115
Writing the Compilation Function for the New Tag. . . . . . . . . . . . . . 116
Writing the LatestContentNode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Registering and Using the New Tag. . . . . . . . . . . . . . . . . . . . . . . . . . 120
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

Chapter 7 Finishing the Weblog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

Comments and django.contrib.comments . . . . . . . . . . . . . . . . . . . . . . . . . 123


Implementing Model Inheritance and Abstract Models. . . . . . . . . . . . . . . 123
Installing the Comments Application . . . . . . . . . . . . . . . . . . . . . . . . . 124
Performing Basic Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Retrieving Lists of Comments for Display . . . . . . . . . . . . . . . . . . . . . 127
Moderating Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Using Signals and the Django Dispatcher . . . . . . . . . . . . . . . . . . . . . 129
Building the Automatic Comment Moderator . . . . . . . . . . . . . . . . . . 130
Adding Akismet Support. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Sending E-mail Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Using Django’s Comment-Moderation Features. . . . . . . . . . . . . . . . 138
viii ■CO NTENT S

Adding Feeds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140


Creating the LatestEntriesFeed Class. . . . . . . . . . . . . . . . . . . . . . . . . 140
Generating Entries by Category: A More Complex Feed Example. 144
Looking Ahead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

Chapter 8 A Social Code-Sharing Site. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

Compiling a Feature Checklist. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149


Setting Up the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Building the Initial Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
The Language Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
The Snippet Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Testing the Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Building Initial Views for Snippets and Languages . . . . . . . . . . . . . . . . . . 156
CSS for pygments Syntax Highlighting. . . . . . . . . . . . . . . . . . . . . . . . 158
Views for Languages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
An Advanced View: Top Authors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Improving the View of Top Authors. . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Adding a top_languages View. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

Chapter 9 Form Processing in the Code-Sharing Application . . . . . . 165

A Brief Tour of Django’s Form System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165


A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Validating the Username. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Validating the Password. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Creating the New User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
How Form Validation Works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Processing the Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Writing a Form for Adding Code Snippets. . . . . . . . . . . . . . . . . . . . . . . . . . 174
Writing a View to Process the Form . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Writing the Template to Handle the add_snippet View. . . . . . . . . . 178
Automatically Generating the Form from a Model Definition. . . . . . . . . . 179
Simplifying Templates That Display Forms. . . . . . . . . . . . . . . . . . . . . . . . . 182
Editing Snippets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
■C O N T E N T S ix

Chapter 10 Finishing the Code-Sharing Application. . . . . . . . . . . . . . . . . . 187

Bookmarking Snippets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187


Adding Basic Bookmark Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Creating a New Template Tag: {% if_bookmarked %}. . . . . . . . . . . . . . . 191
Parsing Ahead in a Django Template. . . . . . . . . . . . . . . . . . . . . . . . . 192
Resolving Variables Inside a Template Node. . . . . . . . . . . . . . . . . . . 193
Using RequestContext to Automatically Populate Template Variables. . . 196
Adding the User Rating System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Rating Snippets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Adding an {% if_rated %} Template Tag . . . . . . . . . . . . . . . . . . . . . . 200
Retrieving a User’s Rating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

CHAPTER 11 Practical Development Techniques. . . . . . . . . . . . . . . . . . . . . . . 205

Using Version-Control Systems to Track Your Code . . . . . . . . . . . . . . . . . 205


A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Version-Control Tools and Hosting Options. . . . . . . . . . . . . . . . . . . . 208
Choosing and Using a VCS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Using Isolated Python Environments to Manage Software. . . . . . . . . . . . 209
Using Build Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Using a Deployment Tool. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Simplifying Your Django Development Process. . . . . . . . . . . . . . . . . . . . . 215
Living Without Projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Using Relative Paths in Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Dealing with Settings That Change for Different Environments. . . 218
Unit-Testing Your Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

Chapter 12 Writing Reusable Django Applications . . . . . . . . . . . . . . . . . . . 223

One Thing at a Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224


Staying Focused. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Advantages of Tightly Focused Applications. . . . . . . . . . . . . . . . . . . 225
Developing Multiple Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Drawing the Lines Between Applications. . . . . . . . . . . . . . . . . . . . . . 227
Splitting Up the Code-Sharing Application. . . . . . . . . . . . . . . . . . . . . 228
x ■Contents

Building for Flexibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228


Flexible Form Handling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Flexible Template Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Flexible Post-Form Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Flexible URL Handling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Taking Advantage of Django’s APIs . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Staying Generic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Distributing Django Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Python Packaging Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Writing a setup.py Script with distutils. . . . . . . . . . . . . . . . . . . . . . . . 235
Standard Files to Include in a Package . . . . . . . . . . . . . . . . . . . . . . . 236
Documenting an Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Looking Ahead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
About the Author

nJames Bennett is a web developer at the Lawrence Journal-


World in Lawrence, Kansas, where Django was originally
developed. He is both a regular contributor to and the
release manager for the open source Django project.

xi
About the Technical Reviewer

nBen Ford has been using Django since 2006, in both personal projects and more
“enterprise” settings. Django has also set him on the path of learning Python’s deeper
magic, including metaprogramming, decorators, and descriptors. The journey continues.

xiii
Exploring the Variety of Random
Documents with Different Content
With my repentance; manet alia mente repostum.[37]

Fran. de Med. Now, by my birth, you are a foolish, mad,


And jealous woman.

Brach. You see 'tis not my seeking.

Fran. de Med. Was this your circle of pure unicorn's horn


You said should charm your lord? now, horns upon thee,
For jealousy deserves them! Keep your vow
And take your chamber.

Isab. No, sir, I'll presently to Padua;


I will not stay a minute.

Mont. O good madam!

Brach. 'Twere best to let her have her humour:


Some half day's journey will bring down her stomach,
And then she'll turn in post.

Fran. de Med. To see her come


To my lord cardinal for a dispensation
Of her rash vow, will beget excellent laughter.

Isab. Unkindness, do thy office; poor heart, break:


Those are the killing griefs which dare not speak.
[Exit.

Re-enter Marcello with Camillo.

Mar. Camillo's come, my lord.


Fran. de Med. Where's the commission?
Mar. 'Tis here.
Fran. de Med. Give me the signet. [Francisco de Medicis, Monticelso,
Camillo, and Marcello retire to the back of the stage.
Flam. My lord, do you mark their whispering? I will compound a
medicine, out of their two heads, stronger than garlic, deadlier than
stibium:[38] the cantharides, which are scarce seen to stick upon the
flesh when they work to the heart, shall not do it with more silence
or invisible cunning.
Brach. About the murder?
Flam. They are sending him to Naples, but I'll send him to Candy.

Enter Doctor.

Here's another property too.


Brach. O, the doctor!
Flam. A poor quack-salving knave, my lord; one that should have
been lashed for's lechery, but that he confessed a judgment, had an
execution laid upon him, and so put the whip to a non plus.
Doc. And was cozened, my lord, by an arranter knave than myself,
and made pay all the colourable execution.
Flam. He will shoot pills into a man's guts shall make them have
more ventages than a cornet or a lamprey; he will poison a kiss; and
was once minded, for his master-piece, because Ireland breeds no
poison, to have prepared a deadly vapour in a Spaniard's fart, that
should have poisoned all Dublin.
Brach. O, Saint Anthony's fire.
Doc. Your secretary is merry, my lord.
Flam. O thou cursed antipathy to nature!—Look, his eye's
bloodshed, like a needle a surgeon stitcheth a wound with.—Let me
embrace thee, toad, and love thee, O thou abominable
loathsome[39] gargarism, that will fetch up lungs, lights, heart, and
liver, by scruples!
Brach. No more.—I must employ thee, honest doctor:
You must to Padua, and by the way,
Use some of your skill for us.

Doc. Sir, I shall.

Brach. But, for Camillo?

Flam. He dies this night, by such a politic strain,


Men shall suppose him by's own engine slain.
But for your duchess' death—

Doc. I'll make her sure.

Brach. Small mischiefs are by greater made secure.


Flam. Remember this, you slave; when knaves come to preferment,
they rise as gallowses are raised i' the Low Countries, one upon
another's shoulders. [Exeunt Brachiano, Flamineo, and Doctor.

SCENE II.—The same.

Francisco de Medicis, Monticelso, Camillo, and Marcello.

Mont. Here is an emblem, nephew, pray peruse it:


'Twas thrown in at your window.

Cam. At my window!
Here is a stag, my lord, hath shed his horns,
And, for the loss of them, the poor beast weeps:
The word,[40] Inopem me copia fecit.[41]

Mont. That is,


Plenty of horns hath made him poor of horns.

Cam. What should this mean?


Mont. I'll tell you: 'tis given out
You are a cuckold.

Cam. Is it given out so?


I had rather such report as that, my lord,
Should keep within doors.

Fran. de Med. Have you any children?

Cam. None, my lord.

Fran. de Med. You are the happier:


I'll tell you a tale.

Cam. Pray, my lord.

Fran. de Med. An old tale.


Upon a time Phœbus, the god of light,
Or him we call the Sun, would needs be married:
The gods gave their consent, and Mercury
Was sent to voice it to the general world.
But what a piteous cry there straight arose
Amongst smiths and felt-makers, brewers and cooks,
Reapers and butterwomen, amongst fishmongers,
And thousand other trades, which are annoyed
By his excessive heat! 'twas lamentable.
They came to Jupiter all in a sweat,
And do forbid the bans. A great fat cook
Was made their speaker, who entreats of Jove
That Phœbus might be gelded; for, if now,
When there was but one sun, so many men
Were like to perish by his violent heat,
What should they do if he were married,
And should beget more, and those children
Make fire-works like their father? So say I;
Only I will apply it to your wife:
Her issue, should not providence prevent it,
Would make both nature, time, and man repent it.

Mont. Look you, cousin,


Go, change the air, for shame; see if your absence
Will blast your cornucopia. Marcello
Is chosen with you joint commissioner
For the relieving our Italian coast
From pirates.

Mar. I am much honoured in't.

Cam. But, sir,


Ere I return, the stag's horns may be sprouted
Greater than those are shed.

Mont. Do not fear it:


I'll be your ranger.

Cam. You must watch i' the nights;


Then's the most danger.

Fran. de Med. Farewell, good Marcello:


All the best fortunes of a soldier's wish
Bring you a-ship-board!

Cam. Were I not best, now I am turned soldier,


Ere that I leave my wife, sell all she hath,
And then take leave of her?

Mont. I expect good from you,


Your parting is so merry.

Cam. Merry, my lord! o' the captain's humour right;


I am resolvèd to be drunk this night.
[Exeunt Camillo and Marcello.

Fran. de Med. So, 'twas well fitted: now shall we discern


How his wished absence will give violent way
To Duke Brachiano's lust.

Mont. Why, that was it;


To what scorned purpose else should we make choice
Of him for a sea-captain? and, besides,
Count Lodowick, which was rumoured for a pirate,
Is now in Padua.

Fran. de Med. Is't true?

Mont. Most certain.


I have letters from him, which are suppliant
To work his quick repeal from banishment:
He means to address himself for pension
Unto our sister duchess.

Fran. de Med. O, 'twas well:


We shall not want his absence past six days.
I fain would have the Duke Brachiano run
Into notorious scandal; for there's naught
In such cursed dotage to repair his name,
Only the deep sense of some deathless shame.

Mont. It may be objected, I am dishonourable


To play thus with my kinsman; but I answer,
For my revenge I'd stake a brother's life,
That, being wronged, durst not avenge himself.

Fran. de Med. Come, to observe this strumpet.

Mont. Curse of greatness!


Sure he'll not leave her?
Fran. de Med. There's small pity in't:
Like misletoe on sear elms spent by weather,
Let him cleave to her, and both rot together.
[Exeunt.

SCENE III.—A Room in the House of Camillo.

Enter Brachiano, with a Conjurer.

Brach. Now, sir, I claim your promise: 'tis dead midnight,


The time prefixed to show me, by your art,
How the intended murder of Camillo
And our loathed duchess grow to action.

Con. You have won me by your bounty to a deed


I do not often practise. Some there are
Which by sophistic tricks aspire that name,
Which I would gladly lose, of necromancer;
As some that use to juggle upon cards,
Seeming to conjure, when indeed they cheat;
Others that raise up their confederate spirits
'Bout wind-mills, and endanger their own necks
For making of a squib; and some there are
Will keep a curtal[42] to show juggling tricks,
And give out 'tis a spirit: besides these,
Such a whole realm of almanac-makers, figure-flingers,
Fellows, indeed, that only live by stealth,
Since they do merely lie about stol'n goods,
They'd make men think the devil were fast and loose,
With speaking fustian Latin. Pray, sit down:
Put on this night-cap, sir, 'tis charmed; and now
I'll show you, by my strong commanding art,
The circumstance that breaks your duchess' heart.
A Dumb Show.

Enter suspiciously Julio and Christophero: they draw a curtain


where Brachiano's picture is, put on spectacles of glass, which
cover their eyes and noses, and then burn perfumes before the
picture, and wash the lips; that done, quenching the fire, and
putting off their spectacles, they depart laughing.
Enter Isabella in her night-gown, as to bed-ward, with lights
after her, Count Lodovico, Giovanni, Guidantonio, and others
waiting on her: she kneels down as to prayers, then draws the
curtain of the picture, does three reverences to it, and kisses it
thrice; she faints, and will not suffer them to come near it; dies:
sorrow expressed in Giovanni and Count Lodovico: she is
conveyed out solemnly.

Brach. Excellent! then she's dead.

Con. She's poisonèd


By the fumed picture. 'Twas her custom nightly,
Before she went to bed, to go and visit
Your picture, and to feed her eyes and lips
On the dead shadow. Doctor Julio,
Observing this, infects it with an oil
And other poisoned stuff, which presently
Did suffocate her spirits.

Brach. Methought I saw


Count Lodowick there.

Con. He was: and by my art


I find he did most passionately dote
Upon your duchess. Now turn another way,
And view Camillo's far more politic fate.
Strike louder, music, from this charmèd ground,
To yield, as fits the act, a tragic sound!
The second Dumb Show.

Enter Flamineo, Marcello, Camillo, with four others, as Captains;


they drink healths, and dance: a vaulting-horse is brought into
the room: Marcello and two others whispered out of the room,
while Flamineo and Camillo strip themselves to their shirts, to
vault; they compliment who shall begin: as Camillo is about to
vault, Flamineo pitcheth him upon his neck, and, with the help of
the rest, writhes his neck about; seems to see if it be broke,
and lays him folded double, as it were, under the horse; makes
signs to call for help: Marcello comes in, laments; sends for the
Cardinal and Duke, who come forth with armed men; wonder at
the act; command the body to be carried home; apprehend
Flamineo, Marcello, and the rest, and go, as it were, to
apprehend Vittoria.

Brach. 'Twas quaintly done; but yet each circumstance


I taste not fully.

Con. O, 'twas most apparent:


You saw them enter, charged with their deep healths
To their boon voyage; and, to second that,
Flamineo calls to have a vaulting-horse
Maintain their sport; the virtuous Marcello
Is innocently plotted forth the room;
Whilst your eye saw the rest, and can inform you
The engine of all.

Brach. It seems Marcello and Flamineo


Are both committed.[43]

Con. Yes, you saw them guarded;


And now they are come with purpose to apprehend
Your mistress, fair Vittoria. We are now
Beneath her roof: 'twere fit we instantly
Make out by some back-postern.

Brach. Noble friend,


You bind me ever to you: this shall stand
As the firm seal annexèd to my hand;
It shall enforce a payment.

Con. Sir, I thank you. [Exit Brachiano.


Both flowers and weeds spring when the sun is warm,
And great men do great good or else great harm.
[Exit.

SCENE IV.—The Mansion of Monticelso.

Enter Francisco de Medicis and Monticelso, their Chancellor and


Register.

Fran. de Med. You have dealt discreetly, to obtain the presence


Of all the grave lieger[44] ambassadors,
To hear Vittoria's trial.

Mont. 'Twas not ill;


For, sir, you know we have naught but circumstances
To charge her with, about her husband's death:
Their approbation, therefore, to the proofs
Of her black lust shall make her infamous
To all our neighbouring kingdoms. I wonder
If Brachiano will be here.

Fran. de Med. O fie.


Twere impudence too palpable. [Exeunt.

Enter Flamineo and Marcello guarded, and a Lawyer.

Law. What, are you in by the week? so, I will try now whether thy
wit be close prisoner. Methinks none should sit upon thy sister but
old whore-masters.
Flam. Or cuckolds; for your cuckold is your most terrible tickler of
lechery. Whore-masters would serve; for none are judges at tilting
but those that have been old tilters.
Law. My lord duke and she have been very private.
Flam. You are a dull ass; 'tis threatened they have been very public.
Law. If it can be proved they have but kissed one another—
Flam. What then?
Law. My lord cardinal will ferret them.
Flam. A cardinal, I hope, will not catch conies.
Law. For to sow kisses (mark what I say), to sow kisses is to reap
lechery; and, I am sure, a woman that will endure kissing is half
won.
Flam. True, her upper part, by that rule: if you will win her nether
part too, you know what follows.
Law. Hark; the ambassadors are lighted.
Flam. [Aside]. I do put on this feignèd garb of mirth
To gull suspicion.

Mar. O my unfortunate sister!


I would my dagger-point had cleft her heart
When she first saw Brachiano: you, 'tis said,
Were made his engine and his stalking-horse,
To undo my sister.

Flam. I am a kind of path


To her and mine own preferment.

Mar. Your ruin.

Flam. Hum! thou art a soldier,


Follow'st the great duke, feed'st his victories,
As witches do their serviceable spirits,
Even with thy prodigal blood: what hast got,
But, like the wealth of captains, a poor handful,
Which in thy palm thou bear'st as men hold water?
Seeking to gripe it fast, the frail reward
Steals through thy fingers.

Mar. Sir!

Flam. Thou hast scarce maintenance


To keep thee in fresh shamois.[45]

Mar. Brother!

Flam. Hear me:—


And thus, when we have even poured ourselves
Into great fights, for their ambition
Or idle spleen, how shall we find reward?
But as we seldom find the misletoe
Sacred to physic, or the builder oak,
Without a mandrake by it; so in our quest of gain,
Alas, the poorest of their forced dislikes
At a limb proffers, but at heart it strikes!
This is lamented doctrine.

Mar. Come, come.

Flam. When age shall turn thee


White as a blooming hawthorn—

Mar. I'll interrupt you:—


For love of virtue bear an honest heart,
And stride o'er every politic respect,
Which, where they most advance, they most infect.
Were I your father, as I am your brother,
I should not be ambitious to leave you
A better patrimony.

Flam. I'll think on't.—


The lord ambassadors.
[The Ambassadors pass over the stage severally.
Law. O my sprightly Frenchman!—Do you know him? he's an
admirable tilter.
Flam. I saw him at last tilting: he showed like a pewter candlestick,
fashioned like a man in armour, holding a tilting-staff in his hand,
little bigger than a candle of twelve i' the pound.
Law. O, but he's an excellent horseman.
Flam. A lame one in his lofty tricks: he sleeps a-horseback, like a
poulter.[46]
Law. Lo you, my Spaniard!
Flam. He carries his face in's ruff, as I have seen a serving man carry
glasses in a cypress hatband, monstrous steady, for fear of breaking:
he looks like the claw of a blackbird, first salted, and then broiled in
a candle. [Exeunt.

ACT THE THIRD.


SCENE I.—A Hall in Monticelso's Mansion.

Enter Francisco de Medicis, Monticelso, the six lieger


Ambassadors, Brachiano, Vittoria Corombona, Flamineo, Marcello,
Lawyer, and a Guard.
Mont. Forbear, my lord, here is no place assigned you:
This business by his holiness is left
To our examination. [To Brach.

Brach. May it thrive with you!


[Lays a rich gown under him.

Fran. de Med. A chair there for his lordship!

Brach. Forbear your kindness: an unbidden guest


Should travel as Dutchwomen go to church,
Bear their stools with them.

Mont. At your pleasure, sir.—


Stand to the table, gentlewoman [To Vittoria].—Now, signior,
Fall to your plea.
Law. Domine judex, converte oculos in hanc pestem, mulierum
corruptissimam.
Vit. Cor. What's he?

Fran. de Med. A lawyer that pleads against you.

Vit. Cor. Pray, my lord, let him speak his usual tongue;
I'll make no answer else.

Fran. de Med. Why, you understand Latin.

Vit. Cor. I do, sir; but amongst this auditory


Which come to hear my cause, the half or more
May be ignorant in't.

Mont. Go on, sir.

Vit. Cor. By your favour,


I will not have my accusation clouded
In a strange tongue; all this assembly
Shall hear what you can charge me with.

Fran. de Med. Signior,


You need not stand on't much; pray, change your language.

Mont. O, for God sake!—Gentlewoman, your credit


Shall be more famous by it.

Law. Well, then, have at you!

Vit. Cor. I am at the mark, sir: I'll give aim to you,


And tell you how near you shoot.

Law. Most literated judges, please your lordships


So to connive your judgments to the view
Of this debauched and diversivolent woman;
Who such a black concatenation
Of mischief hath effected, that to extirp
The memory of't, must be the consummation
Of her and her projections,—

Vit. Cor. What's all this?

Law. Hold your peace:


Exorbitant sins must have exulceration.

Vit. Cor. Surely, my lords, this lawyer here hath swallowed


Some pothecaries' bills, or proclamations;
And now the hard and undigestible words
Come up, like stones we use give hawks for physic;
Why, this is Welsh to Latin.

Law. My lords, the woman


Knows not her tropes nor figures, nor is perfect
In the academic derivation
Of grammatical elocution.

Fran. de Med. Sir, your pains


Shall be well spared, and your deep eloquence
Be worthily applauded amongst those
Which understand you.

Law. My good lord,—

Fran. de Med. Sir,


Put up your papers in your fustian bag,—
[Francisco speaks this as in scorn.
Cry mercy, sir, 'tis buckram—and accept
My notion of your learned verbosity.

Law. I most graduatically thank your lordship:


I shall have use for them elsewhere.

Mont. I shall be plainer with you, and paint out


Your follies in more natural red and white
Than that upon your cheek. [To Vittoria.

Vit. Cor. O you mistake:


You raise a blood as noble in this cheek
As ever was your mother's.

Mont. I must spare you, till proof cry "whore" to that.—


Observe this creature here, my honoured lords,
A woman of a most prodigious spirit,
In her effected.

Vit. Cor. Honourable my lord,


It doth not suit a reverend cardinal
To play the lawyer thus.

Mont. O, your trade instructs your language.—


You see, my lords, what goodly fruit she seems;
Yet, like those apples[47] travellers report
To grow where Sodom and Gomorrah stood,
I will but touch her, and you straight shall see
She'll fall to soot and ashes.

Vit. Cor. Your envenomed


Pothecary should do't.

Mont. I am resolved,[48]
Were there a second Paradise to lose,
This devil would betray it.

Vit. Cor. O poor charity!


Thou art seldom found in scarlet.

Mont. Who knows not how, when several night by night


Her gates were choked with coaches, and her rooms
Outbraved the stars with several kind of lights;
When she did counterfeit a prince's court
In music, banquets, and most riotous surfeits?
This whore, forsooth, was holy.

Vit. Cor. Ha! whore! what's that!

Mont. Shall I expound whore to you? sure, I shall;


I'll give their perfect character. They are first,
Sweetmeats which rot the eater; in man's nostrils
Poisoned perfumes: they are cozening alchemy;
Shipwrecks in calmest weather. What are whores!
Cold Russian winters, that appear so barren
As if that nature had forgot the spring:
They are the true material fire of hell:
Worse than those tributes i' the Low Countries paid,
Exactions upon meat, drink, garments, sleep,
Ay, even on man's perdition, his sin:
They are those brittle evidences of law
Which forfeit all a wretched man's estate
For leaving out one syllable. What are whores!
They are those flattering bells have all one tune,
At weddings and at funerals. Your rich whores
Are only treasuries by extortion filled,
And emptied by cursed riot. They are worse,
Worse than dead bodies which are begged at gallows,
And wrought upon by surgeons, to teach man
Wherein he is imperfect. What's a whore!
She's like the guilty counterfeited coin
Which, whosoe'er first stamps it, brings in trouble
All that receive it.

Vit. Cor. This character scapes me.

Mont. You, gentlewoman!


Take from all beasts and from all minerals
Their deadly poison—

Vit. Cor. Well, what then?

Mont. I'll tell thee;


I'll find in thee a pothecary's shop,
To sample them all.

Fr. Am. She hath lived ill.

Eng. Am. True; but the cardinal's too bitter.

Mont. You know what whore is. Next the devil adultery,
Enters the devil murder.

Fran. de Med. Your unhappy


Husband is dead.
Vit. Cor. O, he's a happy husband:
Now he owes nature nothing.

Fran. de Med. And by a vaulting-engine.

Mont. An active plot; he jumped into his grave.

Fran. de Med. What a prodigy was't


That from some two yards' height a slender man
Should break his neck!

Mont. I' the rushes![49]

Fran. de Med. And what's more,


Upon the instant lose all use of speech,
All vital motion, like a man had lain
Wound up three days. Now mark each circumstance.

Mont. And look upon this creature was his wife.


She comes not like a widow; she comes armed
With scorn and impudence: is this a mourning-habit?

Vit. Cor. Had I foreknown his death, as you suggest,


I would have bespoke my mourning.

Mont. O, you are cunning.

Vit. Cor. You shame your wit and judgment,


To call it so. What! is my just defence
By him that is my judge called impudence?
Let me appeal, then, from this Christian court
To the uncivil Tartar.

Mont. See, my lords,


She scandals our proceedings.

Vit. Cor. Humbly thus,


Thus low, to the most worthy and respected
Lieger ambassadors, my modesty
And womanhood I tender; but withal,
So entangled in a cursèd accusation,
That my defence, of force, like Perseus,[50]
Must personate masculine virtue. To the point.
Find me but guilty, sever head from body,
We'll part good friends: I scorn to hold my life
At yours or any man's entreaty, sir.

Eng. Am. She hath a brave spirit.

Mont. Well, well, such counterfeit jewels


Make true ones oft suspected.

Vit. Cor. You are deceived:


For know, that all your strict-combinèd heads,
Which strike against this mine of diamonds,
Shall prove but glassen hammers,—they shall break.
These are but feignèd shadows of my evils:
Terrify babes, my lord, with painted devils;
I am past such needless palsy. For your names
Of whore and murderess, they proceed from you,
As if a man should spit against the wind;
The filth returns in's face.

Mont. Pray you, mistress, satisfy me one question:


Who lodged beneath your roof that fatal night
Your husband brake his neck?

Brach. That question


Enforceth me break silence: I was there.
Mont. Your business?

Brach. Why, I came to comfort her,


And take some course for settling her estate,
Because I heard her husband was in debt
To you, my lord.

Mont. He was.

Brach. And 'twas strangely feared


That you would cozen[51] her.

Mont. Who made you overseer?

Brach. Why, my charity, my charity, which should flow


From every generous and noble spirit
To orphans and to widows.

Mont. Your lust.

Brach. Cowardly dogs bark loudest: sirrah priest,


I'll talk with you hereafter. Do you hear?
The sword you frame of such an excellent temper
I'll sheathe in your own bowels.
There are a number of thy coat resemble
Your common post-boys.

Mont. Ha!

Brach. Your mercenary post-boys:


Your letters carry truth, but 'tis your guise
To fill your mouths with gross and impudent lies.

Serv. My lord, your gown.


Brach. Thou liest, 'twas my stool:
Bestow't upon thy master, that will challenge
The rest o' the household-stuff; for Brachiano
Was ne'er so beggarly to take a stool
Out of another's lodging: let him make
Vallance for his bed on't, or a demi-foot-cloth
For his most reverent moil.[52] Monticelso,
Nemo me impune lacessit. [Exit.

Mont. Your champion's gone.

Vit. Cor. The wolf may prey the better.

Fran. de Med. My lord, there's great suspicion of the murder,


But no sound proof who did it. For my part,
I do not think she hath a soul so black
To act a deed so bloody: if she have,
As in cold countries husbandmen plant vines,
And with warm blood manure them, even so
One summer she will bear unsavoury fruit,
And ere next spring wither both branch and root.
The act of blood let pass; only descend
To matter of incontinence.

Vit. Cor. I discern poison


Under your gilded pills.

Mont. Now the duke's gone, I will produce a letter,


Wherein 'twas plotted he and you should meet
At an apothecary's summer-house,
Down by the river Tiber,—view't, my lords,—
Where, after wanton bathing and the heat
Of a lascivious banquet,—I pray read it,
I shame to speak the rest.
Vit. Cor. Grant I was tempted;
Temptation to lust proves not the act:
Casta est quam nemo rogavit.[53]
You read his hot love to me, but you want
My frosty answer.

Mont. Frost i' the dog-days! strange!

Vit. Cor. Condemn you me for that the duke did love me!
So may you blame some fair and crystal river
For that some melancholic distracted man
Hath drowned himself in't.

Mont. Truly drowned, indeed.

Vit. Cor. Sum up my faults, I pray, and you shall find,


That beauty, and gay clothes, a merry heart,
And a good stomach to a feast, are all,
All the poor crimes that you can charge me with.
In faith, my lord, you might go pistol flies;
The sport would be more noble.

Mont. Very good.

Vit. Cor. But take you your course: it seems you have beggared me
first,
And now would fain undo me. I have houses,
Jewels, and a poor remnant of crusadoes:[54]
Would those would make you charitable!

Mont. If the devil


Did ever take good shape, behold his picture.

Vit. Cor. You have one virtue left,—


You will not flatter me.

Fran. de Med. Who brought this letter?

Vit. Cor. I am not compelled to tell you.

Mont. My lord duke sent to you a thousand ducats


The twelfth of August.

Vit. Cor. 'Twas to keep your cousin


From prison: I paid use for't.

Mont. I rather think


'Twas interest for his lust.

Vit. Cor. Who says so


But yourself? if you be my accuser,
Pray, cease to be my judge: come from the bench;
Give in your evidence 'gainst me, and let these
Be moderators. My lord cardinal,
Were your intelligencing ears as loving
As to my thoughts, had you an honest tongue,
I would not care though you proclaimed them all.

Mont. Go to, go to.


After your goodly and vain-glorious banquet,
I'll give you a choke-pear.

Vit. Cor. O' your own grafting?

Mont. You were born in Venice, honourably descended


From the Vittelli: 'twas my cousin's fate,—
Ill may I name the hour,—to marry you:
He bought you of your father.

Vit. Cor. Ha!


Mont. He spent there in six months
Twelve thousand ducats, and (to my acquaintance)
Received in dowry with you not one julio:[55]
'Twas a hard pennyworth, the ware being so light.
I yet but draw the curtain now to your picture:
You came from thence a most notorious strumpet,
And so you have continued.

Vit. Cor. My lord,—

Mont. Nay, hear me;


You shall have time to prate. My Lord Brachiano—
Alas, I make but repetition
Of what is ordinary and Rialto talk,
And ballated, and would be played o' the stage,
But that vice many times finds such loud friends
That preachers are charmed silent.—
You gentlemen, Flamineo and Marcello,
The court hath nothing now to charge you with
Only you must remain upon your sureties
For your appearance.

Fran. de Med. I stand for Marcello.

Flam. And my lord duke for me.

Mont. For you, Vittoria, your public fault,


Joined to the condition of the present time,
Takes from you all the fruits of noble pity;
Such a corrupted trial have you made
Both of your life and beauty, and been styled
No less an ominous fate than blazing stars
To princes: here's your sentence; you are confined
Unto a house of convertites, and your bawd—
Flam. [Aside]. Who, I?

Mont. The Moor.

Flam. [Aside]. O, I am a sound man again.

Vit. Cor. A house of convertites! what's that?

Mont. A house
Of penitent whores.

Vit. Cor. Do the noblemen in Rome


Erect it for their wives, that I am sent
To lodge there?

Fran. de Med. You must have patience.

Vit. Cor. I must first have vengeance.


I fain would know if you have your salvation
By patent, that you proceed thus.

Mont. Away with her!


Take her hence.

Vit. Cor. A rape! a rape!

Mont. How!

Vit. Cor. Yes, you have ravished justice;


Forced her to do your pleasure.

Mont. Fie, she's mad!

Vit. Cor. Die with these pills in your most cursèd maw
Should bring you health! or while you sit o' the bench
Let your own spittle choke you!—

Mont. She's turned Fury.

Vit. Cor. That the last day of judgment may so find you,
And leave you the same devil you were before!
Instruct me, some good horse-leech, to speak treason;
For since you cannot take my life for deeds,
Take it for words: O woman's poor revenge,
Which dwells but in the tongue! I will not weep;
No, I do scorn to call up one poor tear
To fawn on your injustice; bear me hence
Unto this house of—what's your mitigating title?

Mont. Of convertites.

Vit. Cor. It shall not be a house of convertites;


My mind shall make it honester to me
Than the Pope's palace, and more peaceable
Than thy soul, though thou art a cardinal.
Know this, and let it somewhat raise your spite,
Through darkness diamonds spread their richest light.[56]
[Exeunt Vittoria Corombona, Lawyer, and
Guards.

Re-enter Brachiano.

Brach. Now you and I are friends, sir, we'll shake hands
In a friend's grave together; a fit place,
Being the emblem of soft peace, to atone our hatred.

Fran. de Med. Sir, what's the matter?

Brach. I will not chase more blood from that loved cheek;
You have lost too much already: fare you well. [Exit.
Fran. de Med. How strange these words sound! what's the
interpretation?
Flam. [Aside.] Good; this is a preface to the discovery of the
duchess' death: he carries it well. Because now I cannot counterfeit
a whining passion for the death of my lady, I will feign a mad
humour for the disgrace of my sister; and that will keep off idle
questions. Treason's tongue hath a villainous palsy in't: I will talk to
any man, hear no man, and for a time appear a politic madman.
[Exit.

Enter Giovanni, Count Lodovico, and Attendant.

Fran. de Med. How now, my noble cousin! what, in black!

Giov. Yes, uncle, I was taught to imitate you


In virtue, and you must imitate me
In colours of your garments. My sweet mother
Is—

Fran. de Med. How! where?

Giov. Is there; no, yonder: indeed, sir, I'll not tell you,
For I shall make you weep.

Fran. de Med. Is dead?

Giov. Do not blame me now,


I did not tell you so.

Lod. She's dead, my lord.

Fran. de Med. Dead!

Mont. Blessed lady, thou are now above thy woes!—


Wilt please your lordships to withdraw a little?
[Exeunt Ambassadors.

Giov. What do the dead do, uncle? do they eat,


Hear music, go a hunting, and be merry,
As we that live?

Fran. de Med. No, coz; they sleep.

Giov. Lord, Lord, that I were dead!


I have not slept these six nights.—When do they wake?

Fran. de Med. When God shall please.

Giov. Good God, let her sleep ever!


For I have known her wake an hundred nights,
When all the pillow where she laid her head
Was brine-wet with her tears. I am to complain to you, sir;
I'll tell you how they have used her now she's dead:
They wrapped her in a cruel fold of lead,
And would not let me kiss her.

Fran. de Med. Thou didst love her.

Giov. I have often heard her say she gave me suck,


And it should seem by that she dearly loved me,
Since princes seldom do it.

Fran. de Med. O, all of my poor sister that remains!—


Take him away, for God's sake!
[Exeunt Giovanni and Attendant.

Mont. How now, my lord!

Fran. de Med. Believe me, I am nothing but her grave;


And I shall keep her blessèd memory
Longer than thousand epitaphs.
[Exeunt Francisco de Medicis and Monticelso.

Re-enter Flamineo as if distracted.

Flam. We endure the strokes like anvils or hard steel,


Till pain itself make us no pain to feel.
Who shall do me right now? is this the end of service? I'd rather go
weed garlic; travel through France, and be mine own ostler; wear
sheepskin linings, or shoes that stink of blacking; be entered into the
list of the forty thousand pedlers in Poland.

Re-enter Ambassadors.

Would I had rotted in some surgeon's house at Venice, built upon


the pox as well as on piles, ere I had served Brachiano!
Savoy Am. You must have comfort.
Flam. Your comfortable words are like honey; they relish well in your
mouth that's whole, but in mine that's wounded they go down as if
the sting of the bee were in them. O, they have wrought their
purpose cunningly, as if they would not seem to do it of malice! In
this a politician imitates the devil, as the devil imitates a cannon;
wheresoever he comes to do mischief, he comes with his backside
towards you.
Fr. Am. The proofs are evident.
Flam. Proof! 'twas corruption. O gold, what a god art thou! and O
man, what a devil art thou to be tempted by that cursed mineral!
Your diversivolent lawyer, mark him: knaves turn informers, as
maggots turn to flies; you may catch gudgeons with either. A
cardinal! I would he would hear me: there's nothing so holy but
money will corrupt and putrify it, like victual under the line. You are
happy in England, my lord: here they sell justice with those weights
they press men to death with. O horrible salary!
Eng. Am. Fie, fie, Flamineo! [Exeunt Ambassadors.
Flam. Bells ne'er ring well, till they are at their full pitch; and I hope
yon cardinal shall never have the grace to pray well till he come to
the scaffold. If they were racked now to know the confederacy,—but
your noblemen are privileged from the rack; and well may, for a little
thing would pull some of them a-pieces afore they came to their
arraignment. Religion, O, how it is commedled[57] with policy! The
first bloodshed in the world happened about religion. Would I were a
Jew!
Mar. O, there are too many.
Flam. You are deceived: there are not Jews enough, priests enough,
nor gentlemen enough.
Mar. How?
Flam. I'll prove it; for if there were Jews enough, so many Christians
would not turn usurers; if priests enough, one should not have six
benefices; and if gentlemen enough, so many early mushrooms,
whose best growth sprang from a dunghill, should not aspire to
gentility. Farewell: let others live by begging; be thou one of them
practise the art of Wolner[58] in England, to swallow all's given thee;
and yet let one purgation make thee as hungry again as fellows that
work in a saw-pit. I'll go hear the screech-owl. [Exit.
Lod. [Aside]. This was Brachiano's pander and 'tis strange
That, in such open and apparent guilt
Of his adulterous sister, he dare utter
So scandalous a passion. I must wind him.

Re-enter Flamineo.

Flam. [Aside]. How dares this banished count return to Rome,


His pardon not yet purchased! I have heard
The deceased duchess gave him pension,
And that he came along from Padua
I' the train of the young prince. There's somewhat in't:
Physicians, that cure poisons, still do work
With counter-poisons.

Mar. Mark this strange encounter.

Flam. The god of melancholy turn thy gall to poison,


And let the stigmatic[59] wrinkles in thy face,
Like to the boisterous waves in a rough tide,
One still overtake another.

Lod. I do thank thee,


And I do wish ingeniously[60] for thy sake
The dog-days all year long.

Flam. How croaks the raven?


Is our good duchess dead?

Lod. Dead.

Flam. O fate!
Misfortune comes, like the coroner's business,
Huddle upon huddle.

Lod. Shalt thou and I join house-keeping?

Flam. Yes, content:


Let's be unsociably sociable.

Lod. Sit some three days together, and discourse.

Flam. Only with making faces: lie in our clothes.

Lod. With faggots for our pillows.

Flam. And be lousy.


Lod. In taffata linings; that's genteel melancholy:
Sleep all day.

Flam. Yes; and, like your melancholic hare,


Feed after midnight.—
We are observed: see how yon couple grieve!

Lod. What a strange creature is a laughing fool!


As if man were created to no use
But only to show his teeth.

Flam. I'll tell thee what,—


It would do well, instead of looking-glasses,
To set one's face each morning by a saucer
Of a witch's congealèd blood.

Lod. Precious gue![61]


We'll never part.

Flam. Never, till the beggary of courtiers,


The discontent of churchmen, want of soldiers,
And all the creatures that hang manacled,
Worse than strappadoed, on the lowest felly
Of Fortune's wheel, be taught, in our two lives,
To scorn that world which life of means deprives.

Enter Antonelli and Gasparo.

Anto. My lord, I bring good news. The Pope, on's death-bed,


At the earnest suit of the Great Duke of Florence,
Hath signed your pardon, and restored unto you—

Lod. I thank you for your news.—Look up again,


Flamineo; see my pardon.

Flam. Why do you laugh?


Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like