gpt4 book ai didi

python - 为什么在我使用 Google App Engine 呈现 html 文件后我的 html 文件中没有处理我的 css 命令?

转载 作者:行者123 更新时间:2023-11-28 18:07:22 24 4
gpt4 key购买 nike

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

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

注意-"template"和“图像”还分别包含我首页的 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

这是处理查询“Computer Networks”时发生的事情的处理程序:

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")

最佳答案

你的 css 文件要么没有部署,要么你是应用程序 static resources配置不正确。

例如,在搜索“Computer Networks”之后,相关样式表会产生 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'>

关于python - 为什么在我使用 Google App Engine 呈现 html 文件后我的 html 文件中没有处理我的 css 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19333398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com