Django in Action(MEAP V01) Christopher Trudeau
download
https://ebookmeta.com/product/django-in-action-
meap-v01-christopher-trudeau/
Download full version ebook from https://ebookmeta.com
Welcome
Dear reader,
As afirst time author, it is hard to express just how fun it is to write that
greeting! Thank you for purchasing the MEAP of Django In Action. This
book starts you on your journey with Django, showing you what you need to
get a project going, and proceeds all the way to using third-party libraries to
enhance your website's offerings. This book is for developers who are already
familiar with Python. A basic understanding of HTML tags will also be
beneficial.
Django has been around for over 20 years, and it has been quite the journey.
In that time, a ton of features have been added, making Django one of the
most comprehensive web framework toolkits available. The book is divided
into three parts. The first part gives you a grounding in Django fundamentals
and will get you to a place where you can write your own websites. Part 2 is
about the many features built into Django meaning you have less code to
write. It includes topics such as creating multi-user sites, dealing with user-
uploaded content, and writing automated tests. Part 3 introduces you to a
variety of third-party libraries that will enable you to write more complex
websites. Here you'll learn about REST APIs, HTMX, custom template tags,
and more.
There is a lot of content out there on Django already, but it can be frustrating
trying to piece it all together. This book builds a single project, "RiffMates",
a classified-ads site for musicians seeking bands and bands seeking
musicians. As you add features to the project in each chapter, you'll be
learning something new and gaining handson experience building a Django
site. Each chapter includes exercises, so you can test your learning as you go
along. Sample code and answers to the exercises are available at:
https://github.com/cltrudeau/django-in-action/
Each directory contains a snapshot of the project's progress within the
6.
chapters.
Working on thisbook has been fun, but the true test is whether you find it
useful. I greatly appreciate any feedback. Please post any questions,
comments, suggestions, or bugs (never, never, that's inconceivable!), in
theliveBook Discussion forum. Your early feedback on the book will be
invaluable in ensuring a better final product.
— Christopher Trudeau
In this book
MEAP VERSION 1 About this MEAP Welcome Brief Table of Contents 1
Django unfolds 2 Your first Django site 3 Templates 4 Django ORM 5
Django Admin
Appendix A. Installation and setup Appendix B. Django in a production
environment
7.
1 Django unfolds
Thischapter covers
What the Django Framework is and why to use it
The actions Django performs when you enter a URL in your browser
Server-side rendering vs single page applications
The kinds of projects you can do with Django
You’ve written a brilliant Python script that runs on your local machine and
now want other people be able to use it. You can use magical packaging tools
and send your program to your users, but then you’re still stuck with the
challenge of whether they have Python installed. Python does not come by
default on many computing platforms, and you have the added problem of
making sure the Python version your script requires is installed on your
user’s
Alternatively, you can turn your Python program into a web application. In
this case, your user’s interface becomes a web browser, and those are
installed everywhere. Your users no longer even need to know what Python
is, they simply point their browser at the right URL and can use your
software. To do this, your program needs to be adapted to run on a web
server. This requires a bit of work, but also has the advantage of a single
environment: you are in full control over what version of Python gets run.
If you’ve already got some experience with Python, a great answer to
building web applications is Django. Django is a third-party Python
framework that lets you write code that runs on a web server. Using Django,
you write Python code called a view that is tied to a URL. When your users
visit the URL, the Django view runs and returns results to the user’s browser.
Django does a lot more than that though, it includes tools for doing the
following:
Routing and managing URLs
Encapsulating what code gets run per page visit
8.
Reading and writingto databases
Composing HTML output based on reusable chunks
Writing multi-user enabled sites
Managing user authentication and authorization to your site
Web-based administrative tools that manage all these features
Django started out as a tool for writing newspaper articles at the Lawrence
Journal-World in Lawrence, Kansas. Rather than having each article be a
single file on a web server, the newspaper wanted a way of re-using pieces of
HTML. You don’t want to write the newspaper’s banner in every file, you
want to compose it like you would with code. You also probably don’t want
your reporters writing HTML; it isn’t their expertise.
Django evolved as both a coding framework and a series of tools to manage
web content. Among other things, the framework provides the ability to
compose HTML out of reusable pieces solving the banner problem, and one
of the tools it includes is a web-based interface for the creation of content.
Reporters can write articles without worrying about HTML. Django’s tools
are built on top of the framework, giving you the power to customize them to
suit your needs.
The robustness of the Django framework has lead to widespread industry
adoption. Reddit, YouTube, The Onion, Pinterest, Netflix, Dropbox, and
Spotify are just a few of the organizations that use Django. Sites like these
need scale, and Django has proven itself. Whether you want to build
something small, or hope to become a massive site, Django can help you. It is
a mature platform with a vibrant community focused on a maintaining and
evolving a well-tested, secure framework. To top it all off, the original
developers at the Journal-World open-sourced it, meaning it is freely
available for you to both use and modify for your needs.
1.1 Django’s Parts
Django is built on three core parts:
1. A mapper between URLs and view code
2. An abstraction for interacting with a database
9.
3. A templatingsystem to manage your HTML like code
On top of these three parts is a large selection of tools. The tools include
things like a web interface for modifying content in the database and the code
needed to write multi-user sites. Each of these is built using the core parts.
This means you can incorporate them into your site and modify them the
same way you write your web application.
When a user visits a web page, the web server determines how to respond
based on the URL. In the case of frameworks like Django, the server gets
configured so some, or all of the URLs get handed to the framework. This
hand-off gets done through a generic Python web interface called the Web
Server Gateway Interace (WSGI).
When you visit a Django URL, the web server calls the framework through
WSGI at which point Django is responsible for generating the page response.
The first core part of Django determines what code to call based on the URL.
This is done through a mapping in your Django project. The mapping is
between URLs and response handlers known as views. A view is a function
or class that generates content which Django then parcels as a response to the
web browser. The complete flow starting with the browser request, web
server hand-off via WSGI, Django mapping the URL, to the view
formulating the response object that Django turns into the response for the
browser, is shown in figure 1.1.
Figure 1.1. Django handling a page visit
11.
The mapping betweenURLs and views gets done through a list data
structure inside a Python file. Each mapping gets defined through the
construction of a path object which contains the URL to map, and a reference
to the handling view. Mappings can also be named to reference them
elsewhere in your code.
Visiting a URL causes Django to loop through all the mappings and look for
a match. If there isn’t a match, Django shows a 404 page. If there is a match,
the corresponding view gets invoked.
The vast majority of the code you write for a Django project is the actual
view code. Views return a response object that encapsulates the information
to send back to the browser. The most common of these objects is
HTTPResponse, which returns text over HTTP, the text typically being
HTML.
Inside your view, you determine what the user sees. Part of that may involve
interacting with a database. Your data may be what parts are in your
warehouse, what books in your library, or which users can access which
pages. To facilitate communication with a database, Django includes an
Object Relational Mapping (ORM), the second of the three core parts. This is
an abstraction that allows you to manage content in a database through
Python classes and objects. If your web page requires information from the
database, the ORM is used to look up a QuerySet object that contains
database results.
The third core part is the templating engine, which helps you create and
manage the HTML within the page response. HTML is a fairly verbose text
format often containing a lot of repeated content. Using the templating
engine, you define HTML templates that describe parts of a web page. The
parts get assembled, composed, and reused to form the response to the user.
For example, a navigation bar, or a footer, that appears on every page, only
needs to be defined once and the template engine helps you include it
everywhere. Templates are not HTML specific and are also used for
parameterizing email or anywhere else you wish to manage text like reusable
code.
12.
Consider a webpage that shows the songs released in a given year. The URL
for all the songs in 1942 might be:
http://example.com/song_by_year/1942/. The code for displaying this
page starts with a mapping between the /song_by_year/ portion of the URL
and a function to handle the response. The mapping is capable of parsing the
/1942/ portion of the URL as a parameter, and passing it into the view
function that generates the page. Figure 1.2 shows the parts of the URL
handled by the view and how the view interacts with the ORM.
Figure 1.2. A song-by-year view rendering a web page based on an argument
14.
The song_by_year viewdoes a look-up in the database for all the songs in
1942. The database query gets abstracted through a Song class in the ORM,
and a query gets performed by invoking a function on that class. The result
from the database gets encapsulated in a QuerySet response object containing
all the corresponding songs.
With the data in hand, the view creates the HTML response. It loads the
songs.html template, which inherits from a common template that includes
the look-and-feel for the website. This means songs.html only contains the
parts that are unique to that page. The template engine has a tag language
allowing you to loop over content, generating the rows in an HTML <table>,
populating each row with the information from a song from 1942.
Once the HTML has been rendered, it is packaged in an HTTPResponse object
and sent back to the Django framework. The loading and rendering of a
template is so common that Django even provides shortcuts to do this.
Django uses the response object to construct the data the web server needs for
the browser. This includes all the HTTP headers and the body containing the
HTML. The content gets returned to the web server through WSGI, and the
server sends it down to the browser. That’s how you see your page full of
songs.
1.1.1 Mapping URLs, Django views, and the MVC model
The simplest form of a website is a mapping between a file and a URL. A
web page that shows a picture of a kitten is at least two files: one for the
HTML document and one for the image of the kitten. Simple file-to-URL
mapped sites like this are called static sites. If you want your users to be able
to upload their own images or add comments to your page, your site can no
longer be just static files. A dynamic site is one that determines a page’s
content when it gets visited.
Dynamic sites are more complicated than static ones, they need an interface
for the users to interact with, they need somewhere to store data like
uploaded pictures and comments, and they need logic for knowing how to
combine these into content.
15.
Django’s primary purposeis building dynamic websites. In doing so, it uses a
common architectural pattern for user interfaces known as the Model-View-
Controller (MVC) method. This method breaks software into three pieces as
shown in figure 1.3:
Figure 1.3. Model-View-Controller architectural pattern
4
The gull replied‘Thy Psyche have I seen;
Walking beside the sea she joy’th to bear
A pyx of dark obsidian’s rarest green,
Wherein she gazeth on her features fair.
She is not hence by now six miles at most.’
Then Eros bade him speed, and down the coast
Held on his passage through the buoyant air.
5
With eager eye he search’d the salty marge
Boding all mischief from his mother’s glee;
And wondering of her wiles, and what the charge
Shut in the dark obsidian pyx might be.
And lo! at last, outstretch’d beside the rocks,
Psyche as lifeless; and the open box
Laid with the weedy refuse of the sea.
6
He guess’d all, flew down, and beside her knelt.
With both his hands stroking her temples wan;
And for the poison with his fingers felt,
And drew it gently from her; and anon
She slowly from those Stygian fumes was freed;
Which he with magic handling and good heed
Replaced in pyx, and shut the lid thereon.
7
19.
‘O Psyche,’ thus,and kissing her he cried,
‘O simple-hearted Psyche, once again
Hast thou thy foolish longing gratified,
A second time hath prying been thy bane.
But lo! I, love, am come, for I am thine:
Nor ever more shall any fate malign,
Or spite of goddess smite our love in twain.
8
‘Let now that I have saved thee twice outweigh
The once that I deserted thee: and thou
Hast much obey’d for once to disobey,
And wilt no more my bidding disallow.
Take up thy pyx; to Aphrodite go,
And claim the promise of thy mighty foe;
Maybe that she will grant it to thee now.
9
‘If she should yet refuse, despair not yet!’
Then Psyche, when she felt his arms restore
Their old embrace, and as their bodies met,
Knew the great joy that grief is pardon’d for;
And how it doth first ecstasy excel,
When love well-known, long-lost, and mournèd well
In long days of no hope, comes home once more.
10
20.
But Eros leapingup with purpose keen
Into the air, as only love can fly,
Bore her to heaven, and setting her unseen
At Aphrodite’s golden gate,—whereby
They came as night was close on twilight dim,—
There left, and bidding her say nought of him,
Went onward to the house of Zeus most high.
11
Where winning audience of the heavenly sire,
Who well disposed to him was used to be,
He told the story of his strong desire;
And boldly begg’d that Zeus would grant his plea,
That he might have sweet Psyche for his wife,
And she be dower’d with immortal life,
Since she was worthy, by his firm decree.
12
And great Zeus smiled; and at the smile of Zeus
All heaven was glad, and on the earth below
Was calm and peace awhile and sorrow’s truce:
The sun shone forth and smote the winter snow,
The flowërs sprang, the birds gan sing and pair,
And mortals, as they drew the brighten’d air,
Marvel’d, and quite forgot their common woe.
13
21.
Yet gave theThunderer not his full consent
Without some words: ‘At length is come the day,’
Thus spake he, ‘when for all thy youth misspent,
Thy mischief-making and thy wanton play
Thou art upgrown to taste the sweet and sour:
Good shall it work upon thee: from this hour
Look we for better things. And this I say,
14
‘That since thy birth, which all we took for bliss,
Thou hast but mock’d us; and no less on me
Hast brought disfavour and contempt, ywiss,
Than others that have had to do with thee:
Till only such as vow’d themselves aloof
From thee and thine were held in good aproof;
And few there were, who thus of shame went free.
15
‘That punishment is shapen as reward
Is like thy fortune: but our good estate
We honour, while we sit to be adored:
And thus ’twas written in the book of Fate.
Not for thy pleasure, but the general weal
Grant I the grace for which thou here dost kneel;
And that which I determine shall not wait.’
16
22.
So wingèd Hermesthrough the heaven he sped,
To warn the high celestials to his hall,
Where they should Psyche see with Eros wed,
And keep the day with feast ambrosial.
And Hermes, flying through the skiey ways
Of high Olympus, spread sweet Psyche’s praise,
And bade the mighty gods obey his call.
17
Then all the Kronian gods and goddesses
Assembl’d at his cry,—and now ’twas known
Why Zeus had smiled,—the lesser majesties
Attending them before his royal throne.
Athena, mistress good of them that know,
Came, and Apollo, warder off of woe,
Who had to Psyche’s sire her fate foreshown;
18
Demeter, giver of the golden com,
Fair Hebe, honour’d at her Attic shrine,
And Artemis with hunting spear and horn,
And Dionysos, planter of the vine,
With old Poseidon from the barren sea,
And Leto, and the lame Hephæstos, he
Himself who built those halls with skill divine.
19
23.
And ruddy Panwith many a quip and quirk
Air’d ’mong those lofty gods his mirth illbred,
Bearing a mighty bowl of cretan work:
Stern Arês, with his crisp hair helmeted,
Came, and retirèd Hestia, and the god
Hermes, with wingèd cap and ribbon’d rod,
By whom the company was heralded.
20
And Hera sat by Zeus, and all around
The Muses, that of learning make their choice;
Who, when Apollo struck his strings to sound,
Sang in alternate music with sweet voice:
And righteous Themis, and the Graces three
Ushering the anger’d Aphrodite; she
Alone of all were there might not rejoice.
21
But ere they sat to feast, Zeus bade them fill
The cup ambrosial of immortal life,
And said ‘If Psyche drink,—and ’tis my will,—
There is an end of this unhappy strife.
Nor can the goddess, whose mislike had birth
From too great honour paid the bride on earth,
Forbid her any more for Eros’ wife.’
22
24.
Then Aphrodite said‘So let it be.’
And Psyche was brought in, with such a flush
Of joy upon her face, as there to see
Was fairer to love’s eye than beauty’s blush.
And then she drank the eternal wine, whose draught
Can Terror cease: which flesh hath never quafft,
Nor doth it flow from grape that mortals crush.
23
And next stood Eros forth, and took her hand,
And kisst her happy face before them all:
And Zeus proclaim’d them married, and outban’d
From heaven whoever should that word miscall.
And then all sat to feast, and one by one
Pledged Psyche ere they drank and cried Well done!
And merry laughter rang throughout the hall.
24
So thus was Eros unto Psyche wed,
The heavenly bridegroom to his earthly bride,
Who won his love, in simple maidenhead:
And by her love herself she glorified,
And him from wanton wildness disinclined;
Since in his love for her he came to find
A joy unknown through all Olympus wide.
25
25.
And Psyche forher fall was quite forgiven,
Since ’gainst herself when tempted to rebel,
By others’ malice on her ruin driven,
Only of sweet simplicity she fell:—
Wherein who fall may fall unto the skies;—
And being foolish she was yet most wise,
And took her trials patiently and well.
26
And Aphrodite since her full defeat
Is kinder and less jealous than before,
And smiling on them both, calls Psyche sweet;
But thinks her son less manly than of yore:
Though still she holds his arm of some renown,
When he goes smiting mortals up and down,
Piercing their marrow with his weapons sore.
27
So now in steadfast love and happy state
They hold for aye their mansion in the sky,
And send down heavenly peace on those who mate,
In virgin love, to find their joy thereby:
Whom gently Eros shooteth, and apart
Keepeth for them from all his sheaf that dart
Which Psyche in his chamber pickt to try.
28
26.
Now in thatsame month Psyche bare a child,
Who straight in heaven was namèd Hedonè
In mortal tongues by other letters styled;
Whom all to love, however named, agree:
Whom in our noble English JOY we call,
And honour them among us most of all,
Whose happy children are as fair as she.
29
ENVOY
IT IS MY PRAYER THAT SHE MAY SMILE ON ALL
WHO READ MY TALE AS SHE HATH SMILED ON ME.
THE GROWTH
OF LOVE
1
Theythat in play can do the thing they would,
Having an instinct throned in reason’s place,
—And every perfect action hath the grace
Of indolence or thoughtless hardihood—
These are the best: yet be there workmen good
Who lose in earnestness control of face,
Or reckon means, and rapt in effort base
Reach to their end by steps well understood.
Me whom thou sawest of late strive with the pains
Of one who spends his strength to rule his nerve,
—Even as a painter breathlessly who strains
His scarcely moving hand lest it should swerve—
Behold me, now that I have cast my chains,
Master of the art which for thy sake I serve.
2
30.
For thou artmine: and now I am ashamed
To have usèd means to win so pure acquist,
And of my trembling fear that might have misst
Thro’ very care the gold at which I aim’d;
And am as happy but to hear thee named,
As are those gentle souls by angels kisst
In pictures seen leaving their marble cist
To go before the throne of grace unblamed.
Nor surer am I water hath the skill
To quench my thirst, or that my strength is freed
In delicate ordination as I will,
Than that to be myself is all I need
For thee to be most mine: so I stand still,
And save to taste my joy no more take heed.
3
The whole world now is but the minister
Of thee to me: I see no other scheme
But universal love, from timeless dream
Waking to thee his joy’s interpreter.
I walk around and in the fields confer
Of love at large with tree and flower and stream,
And list the lark descant upon my theme,
Heaven’s musical accepted worshipper.
Thy smile outfaceth ill: and that old feud
’Twixt things and me is quash’d in our new truce;
And nature now dearly with thee endued
No more in shame ponders her old excuse,
But quite forgets her frowns and antics rude,
So kindly hath she grown to her new use.
4
31.
The very namesof things belov’d are dear,
And sounds will gather beauty from their sense,
As many a face thro’ love’s long residence
Groweth to fair instead of plain and sere:
But when I say thy name it hath no peer,
And I suppose fortune determined thence
Her dower, that such beauty’s excellence
Should have a perfect title for the ear.
Thus may I think the adopting Muses chose
Their sons by name, knowing none would be heard
Or writ so oft in all the world as those,—
Dan Chaucer, mighty Shakespeare, then for third
The classic Milton, and to us arose
Shelley with liquid music in the word.
5
The poets were good teachers, for they taught
Earth had this joy; but that ’twould ever be
That fortune should be perfected in me,
My heart of hope dared not engage the thought.
So I stood low, and now but to be caught
By any self-styled lords of the age with thee
Vexes my modesty, lest they should see
I hold them owls and peacocks, things of nought.
And when we sit alone, and as I please
I taste thy love’s full smile, and can enstate
The pleasure of my kingly heart at ease,
My thought swims like a ship, that with the weight
Of her rich burden sleeps on the infinite seas
Becalm’d, and cannot stir her golden freight.
6
32.
While yet wewait for spring, and from the dry
And blackening east that so embitters March,
Well-housed must watch grey fields and meadows parch,
And driven dust and withering snowflake fly;
Already in glimpses of the tarnish’d sky
The sun is warm and beckons to the larch,
And where the covert hazels interarch
Their tassell’d twigs, fair beds of primrose lie.
Beneath the crisp and wintry carpet hid
A million buds but stay their blossoming;
And trustful birds have built their nests amid
The shuddering boughs, and only wait to sing
Till one soft shower from the south shall bid,
And hither tempt the pilgrim steps of spring.
7
In thee my spring of life hath bid the while
A rose unfold beyond the summer’s best,
The mystery of joy made manifest
In love’s self-answering and awakening smile;
Whereby the lips in wonder reconcile
Passion with peace, and show desire at rest,—
A grace of silence by the Greek unguesst,
That bloom’d to immortalize the Tuscan style:
When first the angel-song that faith had ken’d
Fancy pourtray’d, above recorded oath
Of Israel’s God, or light of poem pen’d;
The very countenance of plighted troth
’Twixt heaven and earth, where in one moment blend
The hope of one and happiness of both.
8
33.
For beauty beingthe best of all we know
Sums up the unsearchable and secret aims
Of nature, and on joys whose earthly names
Were never told can form and sense bestow;
And man hath sped his instinct to outgo
The step of science; and against her shames
Imagination stakes out heavenly claims,
Building a tower above the head of woe.
Nor is there fairer work for beauty found
Than that she win in nature her release
From all the woes that in the world abound:
Nay with his sorrow may his love increase,
If from man’s greater need beauty redound,
And claim his tears for homage of his peace.
9
Thus to thy beauty doth my fond heart look,
That late dismay’d her faithless faith forbore;
And wins again her love lost in the lore
Of schools and script of many a learned book:
For thou what ruthless death untimely took
Shalt now in better brotherhood restore,
And save my batter’d ship that far from shore
High on the dismal deep in tempest shook.
So in despite of sorrow lately learn’d
I still hold true to truth since thou art true,
Nor wail the woe which thou to joy hast turn’d:
Nor come the heavenly sun and bathing blue
To my life’s need more splendid and unearn’d
Than hath thy gift outmatch’d desire and due.
10
34.
Winter was notunkind because uncouth;
His prison’d time made me a closer guest,
And gave thy graciousness a warmer zest,
Biting all else with keen and angry tooth:
And bravelier the triumphant blood of youth
Mantling thy cheek its happy home possest,
And sterner sport by day put strength to test,
And custom’s feast at night gave tongue to truth.
Or say hath flaunting summer a device
To match our midnight revelry, that rang
With steel and flame along the snow-girt ice?
Or when we hark’t to nightingales that sang
On dewy eves in spring, did they entice
To gentler love than winter’s icy fang?
11
There’s many a would-be poet at this hour,
Rhymes of a love that he hath never woo’d,
And o’er his lamplit desk in solitude
Deems that he sitteth in the Muses’ bower:
And some the flames of earthly love devour,
Who have taken no kiss of Nature, nor renew’d
In the world’s wilderness with heavenly food
The sickly body of their perishing power.
So none of all our company, I boast,
But now would mock my penning, could they see
How down the right it maps a jagged coast;
Seeing they hold the manlier praise to be
Strong hand and will, and the heart best when most
’Tis sober, simple, true, and fancy-free.
12
35.
How could Iquarrel or blame you, most dear,
Who all thy virtues gavest and kept back none;
Kindness and gentleness, truth without peer,
And beauty that my fancy fed upon?
Now not my life’s contrition for my fault
Can blot that day, nor work me recompence,
Tho’ I might worthily thy worth exalt,
Making thee long amends for short offence.
For surely nowhere, love, if not in thee
Are grace and truth and beauty to be found;
And all my praise of these can only be
A praise of thee, howe’er by thee disown’d:
While still thou must be mine tho’ far removed,
And I for one offence no more beloved.
13
Now since to me altho’ by thee refused
The world is left, I shall find pleasure still;
The art that most I have loved but little used
Will yield a world of fancies at my will:
And tho’ where’er thou goest it is from me,
I where I go thee in my heart must bear;
And what thou wert that wilt thou ever be,
My choice, my best, my loved, and only fair.
Farewell, yet think not such farewell a change
From tenderness, tho’ once to meet or part
But on short absence so could sense derange
That tears have graced the greeting of my heart;
They were proud drops and had my leave to fall,
Not on thy pity for my pain to call.
14
36.
When sometimes inan ancient house where state
From noble ancestry is handed on,
We see but desolation thro’ the gate,
And richest heirlooms all to ruin gone;
Because maybe some fancied shame or fear,
Bred of disease or melancholy fate,
Hath driven the owner from his rightful sphere
To wander nameless save to pity or hate:
What is the wreck of all he hath in fief,
When he that hath is wrecking? nought is fine
Unto the sick, nor doth it burden grief
That the house perish when the soul doth pine.
Thus I my state despise, slain by a sting
So slight ’twould not have hurt a meaner thing.
15
Who builds a ship must first lay down the keel
Of health, whereto the ribs of mirth are wed:
And knit, with beams and knees of strength, a bed
For decks of purity, her floor and ceil.
Upon her masts, Adventure, Pride, and Zeal,
To fortune’s wind the sails of purpose spread:
And at the prow make figured maidenhead
O’erride the seas and answer to the wheel.
And let him deep in memory’s hold have stor’d
Water of Helicon: and let him fit
The needle that doth true with heaven accord:
Then bid her crew, love, diligence and wit
With justice, courage, temperance come aboard,
And at her helm the master reason sit.
16
37.
This world isunto God a work of art,
Of which the unaccomplish’d heavenly plan
Is hid in life within the creature’s heart,
And for perfection looketh unto man.
Ah me! those thousand ages: with what slow
Pains and persistence were his idols made,
Destroy’d and made, ere ever he could know
The mighty mother must be so obey’d.
For lack of knowledge and thro’ little skill
His childish mimicry outwent his aim;
His effort shaped the genius of his will;
Till thro’ distinction and revolt he came,
True to his simple terms of good and ill,
Seeking the face of Beauty without blame.
17
Say who be these light-bearded, sunburnt faces
In negligent and travel-stain’d array,
That in the city of Dante come to-day,
Haughtily visiting her holy places?
O these be noble men that hide their graces,
True England’s blood, her ancient glory’s stay,
By tales of fame diverted on their way
Home from the rule of oriental races.
Life-trifling lions these, of gentle eyes
And motion delicate, but swift to fire
For honour, passionate where duty lies,
Most loved and loving: and they quickly tire
Of Florence, that she one day more denies
The embrace of wife and son, of sister or sire.
18
38.
Where San Miniato’sconvent from the sun
At forenoon overlooks the city of flowers
I sat, and gazing on her domes and towers
Call’d up her famous children one by one:
And three who all the rest had far outdone,
Mild Giotto first, who stole the morning hours,
I saw, and god-like Buonarroti’s powers,
And Dante, gravest poet, her much-wrong’d son.
Is all this glory, I said, another’s praise?
Are these heroic triumphs things of old,
And do I dead upon the living gaze?
Or rather doth the mind, that can behold
The wondrous beauty of the works and days,
Create the image that her thoughts enfold?
19
Rejoice, ye dead, where’er your spirits dwell,
Rejoice that yet on earth your fame is bright;
And that your names, remember’d day and night,
Live on the lips of those that love you well.
’Tis ye that conquer’d have the powers of hell,
Each with the special grace of your delight:
Ye are the world’s creators, and thro’ might
Of everlasting love ye did excel.
Now ye are starry names, above the storm
And war of Time and nature’s endless wrong
Ye flit, in pictured truth and peaceful form,
Wing’d with bright music and melodious song,—
The flaming flowers of heaven, making May-dance
In dear Imagination’s rich pleasance.
20