Friday, March 29, 2019

Girls Who Code Dynamic HTML Lesson - Lou Person

This lesson will show you how to create a simple dynamic HTML page.  A dynamic HTML page is a web page that is generated by a program running on the server.  A static HTML page is a web page that is a flat file.

First, create your file.  give it your name and enter .py at the end, as an example lou.py
The py at the end of the file name indicates it is a python file.

Insert the following into your file, exactly as it appears.  Copy and paste everything between ##start## and ##end## but do not includes ##start## and ##end## only what's between them.

##start##
#!/bin/python

# Required header that tells the browser how to render the text.

print("Content-Type: text/html\n\n")

# Print a simple message to the display window.

print("<h1>Hello, World!</h1>\n")
##end##

Go to Filezilla.  This time, you will be uploading the file to cgi-bin not html.  When you login, click on cgi-bin.  The server is gwc.daisyware.com.  It should look like this:

Now that the file is uploaded, you can access it as follows: http://gwc.daisyware.com/lou.py 
(Change the name to your name.  Replace the name of the file with the name you used).

Next, we are going to create another file to add two variables together and display the results.
First, create another file with your name and the number 2, e.g. lou2.py
Enter the following in the file (everything between ##start## and ##end##(

##start##
#!/bin/python

# Required header that tells the browser how to render the text.
print("Content-Type: text/html\n\n")  

# Print a simple message to the display window.
print("<h1>Hello, World!<h1>\n")
var1=2
var2=3
var3=var1 + var2
print("<h1>The value is: \n")
print(var3)
print("</h1>\n")

##end##

Upload the file to the cgi-bin directory using Filezilla and access it as follows: http://gwc.daisyware.com/cgi-bin/lou2.py 
(Change the name to your name.  Replace the name of the file with the name you used).