You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -23,7 +23,7 @@ In this tutorial you will learn how to create a
23
23
[static website](/static-site-generator.html) from scratch
24
24
using [Pelican](/pelican.html).
25
25
26
-
<imgsrc="/img/170605-static-sites-pelican/gunship-bootstrap-css.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles page after Bootstrap CSS has been added.">
26
+
<imgsrc="/img/170609-static-sites-pelican/gunship-bootstrap-css.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles page after Bootstrap CSS has been added.">
27
27
28
28
Our simple static site will have pages that look like the above screenshot
29
29
but the entire site can be easily customized and expanded with your own design
@@ -80,7 +80,7 @@ source staticsite/bin/activate
80
80
When activated the virtualenv should prepend its name to your command prompt,
81
81
as shown in the following screenshot of my terminal.
82
82
83
-
<imgsrc="/img/170605-static-sites-pelican/activate-virtualenv.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Create and activate the Python virtual environment.">
83
+
<imgsrc="/img/170609-static-sites-pelican/activate-virtualenv.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Create and activate the Python virtual environment.">
84
84
85
85
Install the appropriate dependencies after your virtualenv is activated.
86
86
Use the `pip` command to install Pelican and Markdown, which will also
@@ -199,7 +199,7 @@ The Pelican development server will start serving up your site with a
199
199
daeman process. Go to [localhost:8000](http://localhost:8000) in your web
200
200
browser and you will see the first version of your static site.
201
201
202
-
<imgsrc="/img/170605-static-sites-pelican/default-style.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Default styling on the Pelican static site.">
202
+
<imgsrc="/img/170609-static-sites-pelican/default-style.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Default styling on the Pelican static site.">
203
203
204
204
What if you don't have `make` installed on your system? Change into the
205
205
`output` directory and use the `python -m http.server` command to use the
@@ -252,8 +252,8 @@ the following content.
252
252
title: Gunship
253
253
slug: gunship
254
254
category: bands
255
-
date: 2017-06-05
256
-
modified: 2017-06-06
255
+
date: 2017-06-09
256
+
modified: 2017-06-09
257
257
258
258
259
259
[Gunship](https://www.gunshipmusic.com/) is a *retro synthwave* artist out of the UK.
@@ -334,7 +334,7 @@ python -m http.server
334
334
335
335
Our first post in all its glory...
336
336
337
-
<imgsrc="/img/170605-static-sites-pelican/gunship-first-post.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Gunship as our first band post on retro synthwave static site.">
337
+
<imgsrc="/img/170609-static-sites-pelican/gunship-first-post.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Gunship as our first band post on retro synthwave static site.">
338
338
339
339
You can change the HTTP server port binding by adding a number after the
340
340
command, if you want to serve more than one static site at a time or you
@@ -391,13 +391,13 @@ python -m http.server
391
391
392
392
Head back to the browser and refresh to view the updated configuration.
393
393
394
-
<imgsrc="/img/170605-static-sites-pelican/updated-configuration.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="New links created by the pelicanconf.py configuration settings file.">
394
+
<imgsrc="/img/170609-static-sites-pelican/updated-configuration.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="New links created by the pelicanconf.py configuration settings file.">
395
395
396
396
What happens when we click on the blog post title? It takes us to a
<imgsrc="/img/170605-static-sites-pelican/gunship-post.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Gunship subpage for the site.">
400
+
<imgsrc="/img/170609-static-sites-pelican/gunship-post.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Gunship subpage for the site.">
401
401
402
402
Alright, we updated some basic site-wide data, but our site really could
403
403
use a change of paint.
@@ -414,64 +414,66 @@ Create a new directory under your project directory that is named
414
414
`templates` is where our [Jinja2](/jinja2.html) templates will be stored and
415
415
can override the default theme.
416
416
417
-
...base.html...
418
-
419
-
```jinja2
420
-
```
421
-
422
-
Within `theme/templates` create a file named `article.html` that will have a
423
-
different theme for blog posts than the rest of the site. Fill `article.html`
424
-
with the following Jinja2 markup.
417
+
Start by creating a file named `base.html` which will store the boilerplate
418
+
used by templates across the site.
425
419
426
420
```jinja2
427
421
<!DOCTYPE html>
428
422
<html lang="en">
429
423
<head>
430
-
<title>{{ article.title }}</title>
424
+
<title>{% block title %}{% endblock %}</title>
431
425
</head>
432
426
<body>
433
427
<div class="container">
434
-
<div class="row">
435
-
<div class="col-md-8">
436
-
<h1>{{ article.title }}</h1>
437
-
<label>Posted on <strong>{{ article.date }}</strong></label>
438
-
{{ article.content }}
439
-
</div>
440
-
</div>
428
+
{% block content %}{% endblock %}
441
429
</div>
442
430
</body>
443
431
</html>
444
432
```
445
433
434
+
Within `theme/templates` create a file named `article.html` that will have a
435
+
different theme for blog posts than the rest of the site. Fill `article.html`
436
+
with the following Jinja2 markup.
437
+
438
+
```jinja2
439
+
{% extends "base.html" %}
440
+
441
+
{% block title %}{{ article.title }}{% endblock %}
442
+
443
+
{% block content %}
444
+
<div class="row">
445
+
<div class="col-md-8">
446
+
<h1>{{ article.title }}</h1>
447
+
<label>Posted on <strong>{{ article.date }}</strong></label>
448
+
{{ article.content }}
449
+
</div>
450
+
</div>
451
+
{% endblock %}
452
+
```
453
+
446
454
Next we will use a Jinja2 template to override the default `index.html` main
447
455
page. Again within the `theme/templates` directory, create a file named
448
456
`index.html` with the following markup.
449
457
450
458
```jinja2
451
-
<!DOCTYPE html>
452
-
<html lang="en">
453
-
<head>
454
-
<title>{{ SITENAME }}</title>
455
-
<!-- Latest compiled and minified Bootstrap CSS -->
<imgsrc="/img/170609-static-sites-pelican/index-no-styling.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="The index.html page without any styling applied.">
492
494
493
-
Click on the Gunship post however and we see that the `article.html`
494
-
"styling" has been applied to the page.
495
+
Click on the title of the Gunship post. This page uses the `article.html`
496
+
template, although it's hard to tell because there is no
497
+
[CSS](/cascading-style-sheets.html) applied to the page.
495
498
496
-
<imgsrc="/img/170605-static-sites-pelican/gunship-no-styling.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles have an entirely different theme based on article.html markup.">
499
+
<imgsrc="/img/170609-static-sites-pelican/gunship-no-styling.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles have an entirely different theme based on article.html markup.">
497
500
498
501
Pretty sparse! We can at least add the Bootstrap CSS to the HTML to
499
502
align our content.
500
503
501
-
Within `article.html`, add the following line for Bootstrap under
502
-
`<title>{{ article.title }}</title>`.
504
+
Within `base.html`, add the following line for Bootstrap under
505
+
`<title>{% block title %}{% endblock %}</title>` and above `</head>`.
503
506
504
507
```jinja2
505
508
<!-- Latest compiled and minified Bootstrap CSS -->
@@ -508,13 +511,13 @@ Within `article.html`, add the following line for Bootstrap under
508
511
509
512
Regenerate the site and refresh the Gunship page.
510
513
511
-
<imgsrc="/img/170605-static-sites-pelican/gunship-bootstrap-css.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles page after Bootstrap CSS has been added.">
514
+
<imgsrc="/img/170609-static-sites-pelican/gunship-bootstrap-css.png"width="100%"class="technical-diagram img-rounded"style="border:1pxsolid#ccc"alt="Articles page after Bootstrap CSS has been added.">
512
515
513
516
Well at least our design has moved from 1996 to 2001. I am sure you can
514
517
do a whole lot more to improve your own site's design.
515
518
516
-
The new `article.html`is not much of a theme for now but it at least
517
-
provides a fresh start for completely customized blog posts.
519
+
The new `base.html`does not provide much of a theme yet but it at least
520
+
provides a fresh start for completely customized sites.
518
521
519
522
520
523
## What's next?
@@ -533,5 +536,5 @@ on Twitter
533
536
or [@mattmakai](https://twitter.com/mattmakai).
534
537
535
538
See something wrong in this blog post? Fork
536
-
[this page's source on GitHub](https://github.com/mattmakai/fullstackpython.com/blob/master/content/posts/170605-static-sites-pelican.markdown)
539
+
[this page's source on GitHub](https://github.com/mattmakai/fullstackpython.com/blob/master/content/posts/170609-static-sites-pelican.markdown)
0 commit comments