If you are linking a route function named home to a Button, which of the following would be correct ways of specifying the second argument?
Button("Home", ___)
Select every answer that applies, then check.
Button in the reading points at its route with a quoted string, e.g. Button("Increase", "index").DrafterIssues question's own Button("Clear", clear_value) shows (no parentheses needed).home immediately, embedding whatever Page it returns right now, instead of deferring execution until the button is clicked.home immediately, for the same reason home() does; adding the state argument doesn't delay execution until a click.home is just a name in the surrounding program.In the program below, which of the following statements are true about when the home route function is executed/called?
from drafter import *
@route
def index(state: str) -> Page:
return Page("Welcome!", Button("Next Page", "next_page"))
@route
def next_page(state: str) -> Page:
return Page("This is the next page.", Button("Go Home", "home"))
@route
def home(state: str) -> Page:
return Page("This is the home page.", "The end.")
start_server("")
Select every answer that applies, then check.
@route only registers it; nothing calls home before start_server starts serving pages.home included, only runs once the server is up and a page is requested or a button is clicked.index, not home."next_page", so it calls next_page, not home."home", so clicking it is exactly what calls the home function.next_page only builds a Button that names "home" as a route; it does not call home itself.In the Drafter program below, which names must match exactly for the program to work correctly?
from drafter import *
@route
def index(___: ___) -> Page:
return Page(1, Div(
TextBox(___),
Button(___, ___)
))
@route
def about(___: ___, feedback: str) -> Page:
return Page(2, "Thank you for your input!")
start_server(0)
Select every answer that applies, then check.
index, but nothing in the reading states that this exact name is required.TextBox feeds need a specific name.Page(1, ...), start_server(0)), and other readings use int or str state just as validly.TextBox's name is matched to a parameter in the route it submits to; here that route is about, whose extra parameter is named feedback.TextBox in the reading takes a quoted string, e.g. TextBox("guess"), not a bare name.about route, and Drafter accepts a route either as a quoted string or as the bare function name.Which of the following statements describe issues in the following code?
from drafter import *
@route
def index(state: int) -> str:
return Page(state, Div(
"Current number:",
bold(state),
TextBox("new_value"),
Button("Set", "set_value"),
Button("Clear", clear_value)
))
@route
def set_value(state: int, new_value: int) -> Page:
return index(new_value)
@route
def clear_value(state: int) -> Page:
return index(0)
start_server(7)
Select one answer, then check.
bold(str(state)); here bold(state) passes the raw integer instead.TextBox submits, so typing this parameter int is exactly how you ask for a number back.index to build the next page is the pattern the "Multiple Routes" example itself uses (return index(state + 1)).Button; the bare names are correct as written.start_server(7).Which statement best describes how State works in Drafter applications?
Select one answer, then check.
Page."next_state value and returns it through Page; the original state parameter itself is never reassigned in place.