Lecture 30

Planning our web app

MCS 275 Spring 2024
Emily Dumas

View as:   Presentation   ·   PDF-exportable  ·   Printable

Lecture 30: Planning our web app

Reminders and announcements:

  • Please install Flask, e.g. with
    python3 -m pip install Flask
    in preparation for using it in class soon.
  • Homework 10 due tomorrow.

Today

Create the rough design for a web application we'll write in Python in the next few lectures.

Continue study of HTML and CSS by making some mockups of the user interfaces.

Toy models

I will prioritize making a working example that uses things we've discussed in the course.

That will mean skipping some natural features (e.g. authentication).

We will also avoid some things for time reasons (JS) or because they would hide the use of course material (e.g. SQLAlchemy).

Task list

Recall we made a terminal-based task list application in lecture 28.

It was based on this model:

  • We maintain a database of tasks
  • A task can be in the state "done" or "not done"
  • Basic operations are list tasks, add a task, modify task state

Task list 2.0

Idea: A web-based task list application based on the following model.

  • Multiple users: each is identified by a user name
  • We maintain a database of tasks, each one has:
    • an owner (username)
    • a state ("waiting", "in progress", "done")
    • a privacy level ("private", "public")
  • Users can view and modify the tasks they own
  • Users can view public tasks of other users

Simplification

We won't build any user account system (login/logout).

Instead, we'll just make the username part of the URL you use to access each part of the application.

Putting "ddumas" in the correct part of the URL takes the place of logging in as ddumas.

App name?

Let's try a Business Name Generator.

UI Mockups

Let's make some HTML+CSS documents that look like the applications we're planning to build.

Later, we'll use these as the starting point for the HTML the app will generate.

CSS

Recall: A language that styles HTML. Basic syntax is


        SELECTOR {
            PROPERTY1: VALUE1;
            PROPERTY2: VALUE2;
        }
    

Elements that match the SELECTOR will have their styling changed by adjusting values of the given properties (things like color, font size, border).

CSS has a complex system of units for values like distances and sizes.


        body {
            font-family: "Verdana", sans-serif;
            background: #C0C0C0;
        }
        p {
            border: 1px solid #000000;
        }
    

The body element of the document (hence everything) will use the font called "Verdana", or if that isn't available, some sans serif font.

The body will be displayed with a light gray background.

Each paragraph will be surrounded by a 1-pixel black border.

Hex colors

The color code

#789ABC

means

  • Amount of red = 0x78 = 120 out of 255
  • Amount of green = 0x9A = 154 out of 255
  • Amount of blue = 0xBC = 188 out of 255

Google has a color picker that can be helpful.

CSS properties

There are lots, e.g. color, background, font-family, font-size, width, height, border, margin, margin-top, margin-left, padding, padding-left, ...

CSS properties reference at w3schools

Applying a stylesheet

You can embed a stylesheet (block of CSS) directly in HTML by placing it inside <style> within <head>.

Or you can use the HTML <link> tag to specify the CSS can be found at another URL (e.g. is in another file).


        <link rel="stylesheet" href="mysite.css">
    

Like <style>, <link> should go in the header.

The latter approach makes stylesheets reusable.

id

An HTML element in a document can be given a unique identifier with the id attribute.


        <p id="selector-intro">Let's talk about CSS selectors...</p>
    

If two elements have same id, your HTML is invalid.

You can link to an element within a document by id e.g.


            We discuss <a href="#selector-intro">selectors</a> below.
        

class

You can create classes (categories) for elements in a HTML document. Mainly used so items in a category (e.g. important, outdated, footnote) can be styled differently (e.g. red, faded, small text).

Specify the category of an element using the class attribute.


        <p class="urgent-warning">Rabid squirrels on the loose!</p>
    

No need to declare classes in advance, nor to refer to every class in your CSS.

class and id selectors

Apply class- or id-specific styles in CSS:


        /* Text in paragraphs is orange */
        p { color: #FFA500; }

        /* Paragraphs of class "urgent-warning" have big, red
           text. This overrides the previous line, as the more
           specific selector gets precedence.  */
        p.urgent-warning { color: #FF0000; font-size: 120%; }

        /* The paragraph with id "selector-intro" is bold */
        p#selector-intro { font-weight: bold; }
    

child and descendant selectors


        div ul {
            /* style for any ul that has
               a div ancestor */
        }
        div > ul {
            /* style for any ul that has
               a div as its parent */
        }
        ul ul {
            /* style for ul inside another ul */
        }
    

Many other selectors

first-child, only-child, selection by adjacency, values of attributes, ...

w3schools CSS selectors reference

Python's built-in HTTP server

python3 -m http.server

Opens a web server that serves files in the current directory and its subdirectories.

Visit http://localhost:8000/ in a browser (or substitute other port number shown in startup message) to see index.html.

Firewall rules typically prevent incoming connections from the internet (and maybe the local network too). That's good! Or

python3 -m http.server --bind 127.0.0.1

will make sure it only listens for connections from the same machine.

References

  • UIC course IT 202 teaches web design properly
    • (whereas for us it is a vehicle to demonstrate Flask)
  • HTML tutorial from W3Schools (all in-browser)
  • jsfiddle
  • Countless web design books in the O'Reilly technical library (free to anyone with a UIC email address).

Revision history

  • 2023-04-03 Finalization of the 2023 lecture this was based on
  • 2024-03-25 Initial publication