二手产品经理

二手产品经理

THIS IS RENO

GET - 83 days - Learn Python online for 100 days

Record#

  1. Today is programming practice, adjusting the code for Day 77.
  2. By passing different parameters, the background color is displayed differently.
  3. Today's programming practice went smoothly. The thinking process was correct during the writing process, but there are still some areas where the syntax is not proficient and needs improvement.

CODE#

main.py#

from flask import Flask, redirect, request

app = Flask(__name__, static_url_path="/static")


def bgcolor(s):
    if s == 'default':
        color = 'style="background-color:#708090"'
    elif s == 'green':
        color = 'style="background-color:#90EE90"'
    elif s == 'blue':
        color = 'style="background-color:#B0C4DE"'
    else:
        color = 'style="background-color:#fff"'
    return color


@app.route('/')
def index():
    blogtitle = "R's Blog"
    link1 = "/link1?color=blue"
    link2 = "/link2?color=green"
    f = open("template/index.html", "r")
    page = f.read()
    f.close
    page = page.replace("{blogtitle}", blogtitle)
    page = page.replace("{link1}", link1)
    page = page.replace("{link2}", link2)
    return page


@app.route('/link1', methods=["GET"])
def link1():
    s = request.args
    color = bgcolor(s["color"])
    title = "link1"
    blogdate = "Day 56 Solution"
    text = "texttexttexttexttexttexttexttexttexttexttext"
    home = "/home"
    page = ""
    f = open("template/blog.html", "r")
    page = f.read()
    f.close()
    page = page.replace("{title}", title)
    page = page.replace("{blogdate}", blogdate)
    page = page.replace("{text}", text)
    page = page.replace("{home}", home)
    page = page.replace("{color}", color)
    return page


@app.route('/link2', methods=["GET"])
def link2():
    s = request.args
    color = bgcolor(s["color"])
    title = "link2"
    blogdate = "Day 57 Solution"
    text = "texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext"
    home = "/home"
    page = ""
    f = open("template/blog.html", "r")
    page = f.read()
    f.close()
    page = page.replace("{title}", title)
    page = page.replace("{blogdate}", blogdate)
    page = page.replace("{text}", text)
    page = page.replace("{home}", home)
    page = page.replace("{color}", color)
    return page


@app.route("/home")
def seventySeven():
    return redirect("https://replit.com/@DengLe/python100day77#main.py")


app.run(host='0.0.0.0', port=81)


index.html#

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>{blogtitle}</title>
  <link href="/static/css/portfolio.css" rel="stylesheet" type="text/css" />
</head>

<body>
  <h1>{blogtitle}</h1>
  <p><a href={link1}>Link1</a></p>
  <p><a href={link2}>Link2</a></p>
</body>

</html>

blog.html#

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Blog</title>
  <link href="/static/css/portfolio.css" rel="stylesheet" type="text/css" />
</head>

<body {color}>

  <h1>{title}</h1>
  <h2>{blogdate}</h2>
  <p>{text}</p>
<a href="{home}">Page Home</a>
  
</body>

</html>
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.