m0_68929701 2022-10-12 12:50 采纳率: 37.5%
浏览 39
已结题

使用Flask搭建一个web服务器并测试

编写Flask实例运行,要求在服务器运行该网https://pythonscraping.com/pages/page3.html
打开网址:http://localhost:5000/

  • 写回答

3条回答 默认 最新

  • 凯歌响起 2022-10-12 13:20
    关注

    代码层次

    img


    html代码

    <html>
    <head>
    <style>
    img{
        width:75px;
    }
    table{
        width:50%;
    }
    td{
        margin:10px;
        padding:10px;
    }
    .wrapper{
        width:800px;
    }
    .excitingNote{
        font-style:italic;
        font-weight:bold;
    }
    </style>
    </head>
    <body>
    <div id="wrapper">
    
    <img src="{{ url_for('static', filename='logo.jpg')}}" style="float:left;"> 
    <h1>Totally Normal Gifts</h1>
    <div id="content">Here is a collection of totally normal, totally reasonable gifts that your friends are sure to love! Our collection is
    hand-curated by well-paid, free-range Tibetan monks.<p>
    We haven't figured out how to make online shopping carts yet, but you can send us a check to:<br>
    123 Main St.<br>
    Abuja, Nigeria
    </br>We will then send your totally amazing gift, pronto! Please include an extra $5.00 for gift wrapping.</div>
    <table id="giftList">
    <tr><th>
    Item Title
    </th><th>
    Description
    </th><th>
    Cost
    </th><th>
    Image
    </th></tr>
    
    <tr id="gift1" class="gift"><td>
    Vegetable Basket
    </td><td>
    This vegetable basket is the perfect gift for your health conscious (or overweight) friends!
    <span class="excitingNote">Now with super-colorful bell peppers!</span>
    </td><td>
    $15.00
    </td><td>
    <img src="{{ url_for('static', filename='img1.jpg')}}">
    </td></tr>
    
    <tr id="gift2" class="gift"><td>
    Russian Nesting Dolls
    </td><td>
    Hand-painted by trained monkeys, these exquisite dolls are priceless! And by "priceless," we mean "extremely expensive"! <span class="excitingNote">8 entire dolls per set! Octuple the presents!</span>
    </td><td>
    $10,000.52
    </td><td>
    <img src="{{ url_for('static', filename='img2.jpg')}}">
    </td></tr>
    
    <tr id="gift3" class="gift"><td>
    Fish Painting
    </td><td>
    If something seems fishy about this painting, it's because it's a fish! <span class="excitingNote">Also hand-painted by trained monkeys!</span>
    </td><td>
    $10,005.00
    </td><td>
    <img src="{{ url_for('static', filename='img3.jpg')}}">
    </td></tr>
    
    <tr id="gift4" class="gift"><td>
    Dead Parrot
    </td><td>
    This is an ex-parrot! <span class="excitingNote">Or maybe he's only resting?</span>
    </td><td>
    $0.50
    </td><td>
    <img src="{{ url_for('static', filename='img4.jpg')}}">
    </td></tr>
    
    <tr id="gift5" class="gift"><td>
    Mystery Box
    </td><td>
    If you love suprises, this mystery box is for you! Do not place on light-colored surfaces. May cause oil staining. <span class="excitingNote">Keep your friends guessing!</span>
    </td><td>
    $1.50
    </td><td>
    <img src="{{ url_for('static', filename='img6.jpg')}}">
    </td></tr>
    </table>
    </p>
    <div id="footer">
    &copy; Totally Normal Gifts, Inc. <br>
    +234 (617) 863-0736
    </div>
    
    </div>
    </body>
    </html>
    
    

    a.py代码

    from flask import Flask
    from flask import render_template #渲染
    app = Flask(__name__)
    
    @app.route('/')
    def hello_world():
        return render_template('index.html') #把index.html文件读进来,再交给浏览器
        
    if __name__ == "__main__":
        app.run(host='127.0.0.1', port=8080)
    

    运行命令python .\a.py

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月14日
  • 已采纳回答 10月14日
  • 创建了问题 10月12日

悬赏问题

  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥15 pyqt信号槽连接写法
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。