1

因此,我在使用 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")
4

1 回答 1

1

您的 css 文件未部署,或者您的应用程序静态资源配置不正确。

例如,在搜索“计算机网络”后,相关样式表会出现 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'>
于 2013-10-13T05:20:21.440 回答