简体   繁体   English

从Python CGI脚本生成的HTML页面引用CSS

[英]Referring to css from a HTML page generated by a Python CGI script

About a week ago, I inherited a monitoring and notification tool which is written in Python. 大约一周前,我继承了用Python编写的监视和通知工具。 I am tasked with creating a proof of concept for a dashboard based on the data that the tool has collected over the years. 我的任务是根据工具多年来收集的数据为仪表板创建概念证明。 Unfortunately, I am new to Python and have never done CGI programming - so a perfect mismatch. 不幸的是,我是Python的新手,从未做过CGI编程-如此完美的不匹配。 :) I am using tomcat7 because it is already installed in the machine. :)我正在使用tomcat7,因为它已经安装在计算机中。

The problem is that I am not able to get my generated HTML page to read the CSS file. 问题是我无法获取生成的HTML页面来读取CSS文件。 My directory structure under webapps/myapp is as follows: 我在webapps/myapp下的目录结构如下:

$ tree
  .
  ├── graphpages.css
  ├── index.html
  ├── META-INF
  │   └── context.xml
  └── WEB-INF
      ├── cgi
      │   ├── hello_world.cgi
      │   └── page1.cgi
      └── web.xml

I have tried to refer to the CSS in my HTML as follows: 我尝试如下引用HTML中的CSS:

<link rel="stylesheet" type="text/css" media="screen" href="../graph_pages.css" />

Tried moving the file graph_pages.css under WEB-INF/ and also by creating a directory htdocs/ under WEB-INF/ and placing the file inside that. 尝试将文件graph_pages.css移动到WEB-INF/并且还通过在WEB-INF/下创建目录htdocs/并将文件放在其中。 Meaning: 含义:

$ tree
.
+-- index.html
+-- META-INF
¦   +-- context.xml
+-- WEB-INF
    +-- cgi
    ¦   +-- hello_world.cgi
    ¦   +-- page1.cgi
    +-- graphpages.css
    +-- web.xml

and

$ tree
.
+-- index.html
+-- META-INF
¦   +-- context.xml
+-- WEB-INF
    +-- cgi
    ¦   +-- hello_world.cgi
    ¦   +-- page1.cgi
    +-- htdocs
    ¦   +-- graphpages.css
    +-- web.xml

Of course, I updated the generated HTML too. 当然,我也更新了生成的HTML。 But no help at all. 但是根本没有帮助。

My browser is able to open the CSS file in the first directory structure above but not in the other two cases. 我的浏览器能够在上面的第一个目录结构中打开CSS文件,但在其他两种情况下却无法打开。

Please help me understand what the directory structure should be and how I can get the CSS to have an effect on the page. 请帮助我了解目录结构应该是什么以及如何使CSS在页面上起作用。

When having graphpages.css at the root level with index.html use the web root / as the starting point as opposed to a relative path ../ : 在带有index.html的根级别上具有graphpages.css时,请使用Web根/作为起点,而不是相对路径../

<link rel="stylesheet" type="text/css" media="screen" href="/graphpages.css" />

Note: You have some references to graphpages.css and graph_pages.css . 注意:您对graphpages.cssgraph_pages.css有一些参考。 Please make sure you're consistent with the file name 请确保您与文件名一致

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM