【问题标题】:Why aren't my css commands being processed in my html file after I render the html file using Google App Engine?为什么我使用 Google App Engine 渲染 html 文件后,我的 html 文件中没有处理我的 css 命令?
【发布时间】:2013-10-13 18:29:19
【问题描述】:

因此,我在使用 Google App Engine 托管的应用程序中有一个基本表单。当我输入特定查询时,比如“CN”,我希望呈现 CN.html 文件。我已经重定向了我的路径和内容,并使用 if-else 允许在查询“CN”时呈现 CN.html 文件。但是,没有考虑 CN.html 中的所有内联 CSS 命令,当我查询“CN”时,我被重定向到的所有内容都是没有所有 CSS 命令的基本 HTML 文档。此外,图像不会显示。

现在,我已将 CN.html 文件放在我的目录中名为“templates”的文件夹中,并将所有图像放在名为“images”的文件夹中。

注意-“模板”和“图像”还分别包含我的首页的 html 文件及其图像。不过,我认为这应该不是问题,对吧?

在这里,自己查看我的问题的实时示例:

访问 www.deploymentapp.appspot.com 并搜索“计算机网络”。

那么问题出在哪里?


编辑(包括所有源代码文件以便更好地理解)

CN.html

<html>
<head>
    <title>Computer Network</title>
<link rel = "stylesheet" href = "/stylesheets/cn.css" type = "text/css">
</head>
<body>
    <div id='cn'>
        <img src = "/images/CN.jpg" width = '300px' height = '400px'>
    </div>
    <div id = 'cn_heading'>
        <h1>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbspComputer Networks</h1>
        <p class = 'pname'>by Andrew Tanenbaum</p>
    </div>
    <div id = 'buy'>
        <a href = '#'><img src = '/images/buy-now.jpg' width = '300px'     height = '100px'></a>
    <div id = 'details'>
        <p>Authored by : Andrew S. Tanenbaum, David J. Wetherall</p> 
        <p>Publisher : Pearson </p>
        <p>Price : Rs. 550 (Inclusive of taxes)</p>
    </div>

    <div id = 'description'>
            <p><h3>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp  COMPUTER NETWORKS 5TH EDITION</h3>
Computer Networks, Fifth Edition, is the ideal introduction to the networking field. This bestseller reflects the latest networking technologies with a special emphasis on wireless networking, including 802.11, 802.16, Bluetooth&trade, and 3G cellular, paired with fixed-network coverage of ADSL, Internet over cable, gigabit Ethernet, MLPS, and peer-to-peer networks. Notably, this latest edition incorporates new coverage on 3G mobile phone networks, Fiber to the Home, RIFD, delay-tolerant networks, and 802.11 security, in addition to expanded material on Internet routing, multicasting, congestion control, quality of service, real-time transport, and content distribution.

Tanenbaum takes a structured approach to explaining how networks work from the inside out. He starts with an explanation of the physical layer of networking, computer hardware and transmission systems then works his way up to network applications.

Salient Features
<ul>
<li>Wireless networks (802.12 and 802.16)</li>
<li>The 3G networks used by smart phones</li>
<li>RFID and sensor networks</li>
<li>Content Distribution using CDNs</li>
<li>Peer-to-peer networks</li>
<li>Real-time media (from stored, streaming, and live sources)</li>
<li>Internet telephony (voice over IP)</li>
<li>Delay-tolerant networks</li>
    </ul>
</p>
       </div>


        </body>
</html> 

CN.css

#cn
{
    margin-top : 50px;
    margin-left : 50px;
    box-shadow : 5px 5px 5px black;
    width : 300px;

}
#cn_heading
{
    margin-top : -448px;
    margin-left : 425px;

}

.pname
{       font-style : italic;
}

#buy
{
    margin-top : 370px;
    margin-left : 50px;

}
#details
{
    margin-left : 425px;
    margin-top : -450px;
}

#description
{
    margin-left : 425px;
    margin-top : 20px;
}

.yaml 文件

application: deploymentapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /images
  static_dir: images

- url: /stylesheets/
  static_dir: stylesheets

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: latest

这是处理查询“计算机网络”时发生的情况的处理程序:

class CNHandler(webapp2.RequestHandler):
    def write(self, *a, **kw):
        self.response.out.write(*a, **kw)
    def render_str(self, template, **params):
        t = jinja_env.get_template(template)
        return t.render(params)
    def render(self, template, **kw):
        self.write(self.render_str(template, **kw))
    def get(self):
        self.render("CN.html")

【问题讨论】:

  • 我无法搜索 Computer Networks,也无法搜索 CN。事实上,我似乎无法搜索任何东西。没有什么是有效的主题名称!
  • 确保计算机网络中的“C”和“N”大写。之后我将研究其他选项。
  • 我们只能推测问题所在,因为您没有向我们展示任何代码。您的问题可能出现在多个地方,但在不了解应用程序结构(即 url 结构、HTML 如何指定 CSS 路径)的情况下,您要求人们猜测。
  • 我现在已经包含了上面的源代码。问题似乎是我的 CN.html 文件即使在我部署文件后也没有更新。因此无法上传图像和样式。知道为什么吗?

标签: python html css google-app-engine


【解决方案1】:

您的 css 文件未部署,或者您的应用程序 static resources 配置不正确。

例如,在搜索“计算机网络”后,相关样式表会显示 404。 http://www.deploymentapp.appspot.com/cn.css

关于图像问题,您没有指定正确的图像路径。例如:

<img src = "CN.jpg" width = '300px' height = '400px'>

应该是:

<img src = "/images/CN.jpg" width = '300px' height = '400px'>

【讨论】:

  • 现在这很有趣。如上面我编辑的帖子中所述,我已经更改了我的 html 文件中的图像路径。但是,即使在部署了编辑后的文件之后,我仍然看到页面源看到的未编辑版本正在部署。为什么会这样?
  • @ManasChaturvedi 您是否在本地 devappserver 上验证了此行为?您是否验证过您的部署成功并且当前版本已设置为默认版本,因为这是一个部署问题,仅此而已。
  • 不..即使在我的本地服务器上,文件也没有更新。这肯定是一个部署问题……但是如何解决呢?
猜你喜欢
  • 1970-01-01
  • 2022-01-25
  • 2020-10-27
  • 1970-01-01
  • 2014-02-27
  • 2021-12-14
  • 2013-05-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多