Multipage sites in python
Notes/Reminders:
- You can make an html link using <a href="otherpage.html"> text </a>. If the href is just a filename, it will look in the same directory as the current html file. If you want to link to an outside site however, you would need to put the full url.
- If you need a refresher on using Cyberduck to upload files to homer, here is link to some notes on using cyberduck (courtesy of Mr. David Holmes).
Tasks:
-
Using your file explorer of choice (i.e. not python), create a directory called hw18, in the same place as your .py file. NOTE: the .py should be outside the hw18 directory.
-
Write a python function makeNPages(n): that writes out n files,
page_0.html, page_1.html, ... ,
page_n‑1.html.
All of your html files should be created inside your hw18/ directory, which you can do using
open("hw18/page_0.html", "w").
-
Make sure you generate each html page with the following:
- A title corresponding to its number (e.g. "This is page 4").
- A link to the next page (e.g. page 3 should link to page 4). The last page should link back to page 0 instead.
- The text of the link (not the href) should be descriptive (e.g. "link to page 4")
-
Pick a value for n between 3 and 6. Use your .py function to generate that many
pages under your hw18/ directory
-
Use Cyberduck or WinSCP to upload your site (i.e. the entire hw18/directory) to homer, under your public_html folder.
-
Verify that you can see the results at homer.stuy.edu/~yourUsername/hw18/page_0.html. Make sure it's not a local link (i.e. not file://... or C:\...), but is actually up on the internet at homer.stuy.edu.
-
Upload the following to the homework server:
- Your .py file, to the hw slot.
- A link to your webpage, into the comments-to-teacher. Make sure this is a link on homer.stuy.edu/....
- Verify that the link as pasted in the comments-to-teacher box works.
- As usual, mention how long this took and who you worked with, if anyone.
Bonus:
The "hw18" directory must already exist for your code to work.
See if you can upgrade your program to automatically check for and
create that directory if it is not already there.
You will need to import the
'os' module
and
which we have not covered, so this will recover some outside research to figure out how to do.
You may need os.mkdir(), os.makedirs(), and you may need os.path.isdir() or os.path.exists() from the
'os.path' methods