【问题标题】:CSS Stylesheet with Python CGI带有 Python CGI 的 CSS 样式表
【发布时间】:2023-03-29 04:11:02
【问题描述】:

我正在网络浏览器中运行 python cgi 脚本。一切正常,但是一旦代码完成执行,所有 css 样式都会消失(html 表单仍然出现并且工作正常)。我怎样才能解决这个问题?这是我的代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="/css/style.css" type="text/css" charset="utf-8">
    <title>Python Index Match</title>
</head>

<body>
     <form action="/cgi-bin/form.py">
      <tag>Welcome!</tag>
      <p class="text">Please browse for your company file:   <input type="file" name="file1" value="Browse"> </p>
      <span class="btn"></span>
      <p class="text">Please browse for your price export file:   <input type="file" name="file2" value="Browse"> </p>
      <span class="btn"></span>
      <p class="text">What company is this file for?     <select name="dropdown"> </p>
        <option></option>
        <option value="...">...</option>
        <option value="...">...</option>
      </select>
      What would you like to name your new file? (With extension) <input type="text" name="result"><br>
      <br>
      <input type="submit">
    </form>
</body>

</html>

以下是之前和之后的图片:

【问题讨论】:

    标签: python html css cgi


    【解决方案1】:

    您的 CGI 脚本应该向您要显示的页面发出 HTTP“重定向”代码。

    # Do not "print(...)" above this
    location = "http://where/you/want/to/browse"  # URL may be relative
    # The first two "print(...)"
    print("Content-Type: text/html")
    print("Location: {}".format(location))
    print()  # Empty line (important)
    print("<html><body>Redirecting, please wait.</body></html>")
    

    【讨论】:

    • 这就是我所拥有的: print("Content-Type: text/html; charset=utf-8\r") print('\r')
    • 重要的是print("Location ...") 行应该告诉浏览器在给定的URL 加载页面。
    • 并使用 Firefox 或 Chrome 开发工具检查服务器和浏览器之间的真实对话(标题、内容),看看有什么问题。
    猜你喜欢
    • 2014-08-06
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    • 2012-05-20
    • 2021-08-03
    相关资源
    最近更新 更多