Giter Club home page Giter Club logo

guestbook's Introduction

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 are displayed.

In 2015 we have server-side languages like Ruby and Python, as well as client-side languages like JavaScript that can do this for us with ease without using cgi. This project is just a little homage to what the web was only a decade or so ago.

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 cloning it within the graphical GitHub client for Windows or Mac

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.

Check the 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:

pip freeze

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. The line: 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):

python3 database.py

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 PORT within the server file.

Now, check out script.py within the cgi-bin folder. The only thing you need to do is make sure the first line is correct. Currently it reads #!/usr/bin/env python3. This statement needs to be at the top of script.py so cgi knows what python version it is using.

Know that 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: python3 server.py

Navigate to 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

Changelog:

  • 13/01/2014: Guestbook released
  • 15/01/2014: Minor updates: Merged #14 and made all code PEP8 compliant

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.