What is a "Guestbook"?
When I first started using the Internet, guestbooks were popular. I'd be able to go to a website like Lissa Explains (which serves as the inspiration for this project) and leave a message with my name and a comment to the author of the website. It was a way of messaging people before you had your Facebooks and your Twitters.
For me, it was my first understanding that people all over the world could converge at the same place at the same time, to talk to each other.
What is "cgi"?
Common Gateway Interface (CGI) was what these original guestbooks were powered on. CGI was introduced in 1993 and kickstarted the move from websites just displaying static HTML (unmodified by scripts) to being able to run scripts on your web server and displaying the results on your website.
In this project; the script
script.py fetches the guestbook posts within the database, and displays them within the
index.html template. I have not written
the HTML for each individual post within the index template, the script does that
for me. The cgi server within
server.py allows me to do this on the website itself,
each time someone visits the guestbook the cgi script is activated and the posts
How can I use this guestbook?
NB: These instructions only cover running the guestbook locally. I'd like to write instructions on running this project on a free application hosting service like Heroku. Help with this is appreciated.
Step One: Grab the code!
You can do this either by cloning the repository if you're familiar with the command line
git clone https://github.com/Charlotteis/guestbook.git
OR by downloading the .zip file directly
Step Two: Install the required packages!
I recommend working within a virtual environment when you work with this code, because it keeps all your dependencies nice and tidy and things are less likely to break.
requirements.txt file for the required dependencies.
The only one we are using for this application is peewee
which helps to manage our guestbook database. To install peewee you will need to have [pip]
(https://pypi.python.org/pypi/pip) already installed.
Within your virtual environment run the following command:
pip install -r requirements.txt
You can check to make sure the requirements are installed by running:
This should display peewee as the only package installed.
Step Three: Create your database!
First, check out the
database.py file. This is what we will run to create our database.
DATABASE = "guestbook.db" sets the name of your database.
Second, check out the dummy posts that will be created when you run this file. Unless you change it, it will create some default posts in my name. Feel free to change the details or delete these dummy posts altogether!
Thirdly, uncomment the single line of code
create_tables(). This will make sure
that a database is created for you with your chosen name so you can work with the guestbook.
Lastly, run the following in your terminal (within the virtual env and project directory):
If you see
"Created the database!" then you have successfully created your database!
You can now comment out
create_tables(). If you want to re-create your database
you can delete the database file, uncomment
create_tables() and run
python3 database.py again.
Step Four: Run the guestbook!
Take a look at the
server.py file. It's a small file that will allow you to run
the files within this project locally on your machine. I've made it so the project files will run on localhost:8000. Feel free to change the
within the server file.
Now, check out
script.py within the
The only thing you need to do is make sure the first line is correct. Currently it
#!/usr/bin/env python3. This statement needs to be at the top of script.py
so cgi knows what python version it is using.
script.py must live within the cgi-bin folder or else it won't work!
Now, we're ready to run our guestbook!
In your terminal, type:
http://localhost:8000/cgi-bin/script.py and you should see the guestbook in all it's glory! It should look something like this
With thanks to:
- @tef for the idea to go "Web 1.0" and use cgi in the first place as well as helping me debug
- @jennschiffer for creating make8bitart.com so I could make sick graphics
- Lissa Explains for still serving as inspiration, after all these years.
- @pkqk and @tom for being patient and helpful
- 13/01/2014: Guestbook released
- 15/01/2014: Minor updates: Merged #14 and made all code PEP8 compliant