CST-111 IT/Python Web Forms & UI
During the course, you will learn that there are several ways to
update data on a remote webserver.
This week, we will configure your webserver to allow copy-and-paste
file transfer. After that, you will copy the file into the webserver directory,
and use Python to automatically add an entry to your blog from Topic 3.
1.
On the webserver, create a subfolder called python in your c:\inetpub\wwwroot
folder. All py files will be stored here.
2.
Create another subfolder called reports also in the c:\inetpub\wwwroot
folder. Your Web Showcase assignment
webpage should be stored here.
3.
Install JES on the Windows 2012 Server.
4.
Now, let’s slowly build newPost.py step by step.
First, we’ll write the code to append to the existing homepage:
Note: You
may need to remove the </body> and </html> tags from your original
iisstart.html file
5.
After running this code, you should check your
webserver homepage. You should notice a new line at the bottom of the document “NewData
from newPost.py”
6.
Once you verify that your webpage has the new
data, we need to create the user input variables and prompt for the data. Add
the following code to the beginning of newPost.py:
7.
With the addition of these three lines, we
prompt the user to enter a Title, Description, and Filename. In order to use
these variables within the addPost function, we first need to modify how we
call the function.
Note: When
we use variables within the function call, they are called arguments.
8.
Next, we need to modify the addPost() definition
to accept these arguments.
9.
Get in the habit now: Every time you make
changes to your code, test it to see if there are any syntax errors. Before
testing your code, think about what you expect it to do at this point. Right
now, our code prompts the user three times, writes some data to your homepage,
and then completes. Ensure your code runs appropriately before moving on.
10.
Now, let’s look a bit closer at line 7.
I have highlighted the python code. Everything else is HTML.
Essentially, we are calling the file.write function and telling it to write
everything between the triple quotes
11.
The only thing left to do is to incorporate our
arguments into the HTML code located in the addPost function. For example,
replace the current file.write line:
Get Free Quote!
281 Experts Online