2012-02-22 53 views
2

Google Appengine 我正在開發一個Google App引擎項目,但我看不到我的css。代碼顯得很簡單。我的風格無法在html頁面上看到。Google App引擎看不到我的CSS文件

我app.yaml文件是如下所示:

application: paymentgateway 
version: 1 
runtime: python 
api_version: 1 

handlers: 

- url: .* 
    script: main.py 

- url: /css 
    static_dir: css 

我main.py文件是如下:如下圖所示

from google.appengine.ext import webapp 
from google.appengine.ext.webapp import util 
from google.appengine.ext.webapp import template 



class MainHandler(webapp.RequestHandler): 
    def get(self): 
     self.response.out.write(template.render('account_type.html','')) 


def main(): 
    application = webapp.WSGIApplication([('/', MainHandler)], 
            debug=True) 
    util.run_wsgi_app(application) 


if __name__ == '__main__': 
    main() 

account_type.html:

<html> 
<head> 
<title></title> 
<link href="css/styles.css" rel="stylesheet" type="text/css"/> 
</head> 
<body> 
<div id="formwrap"> 
<div id="form"> 
<fieldset><legend><h3>Select Country and Account Type</h3></legend> 
<form action="registration_form.html" method="post"> 
<div class="row"> 
<div class="label">Select Country </div><!--end .label--> 
<div class="input"> 
<select name="country" class="detail" > 
<option>--select country--</option> 
<option>Uganda</option> 
<option>Kenya</option> 
<option>Tanzania</option> 
<option>Rwanda</option> 
</select> 
</div><!--end .input--> 
</div><!--end .row--> 

<div class="row"> 
<div class="label">Account Types</div><!--end .label--> 
<div class="input"> 
<input type="radio" name="account" class=""/> 
</div><!--end .input--> 
</div><!--end .row--> 

<div id="submit"> 
<input id="submit" type="submit" name="submit" value="NEXT"> 
</div><!-- end #submit --> 
</form> 
</fieldset> 
</div><!--end #form--> 
</div><!--end #formwrap--> 
</body> 
</html> 

我有我的CSS在一個CSS文件夾。

的styles.css如下圖所示:

body { 
background:#E9E9E9; 
} 


#formWrap { 
    width:720px; 
    margin-top:30px; 
    margin-left:30px; 
    background:#FFF; 
    border:1px solid #f1f1f1; 
    -moz-border-radius:20px; 
    -moz-box-shadow:2px 2px 5px #999; 
    -webkit-border-radius:20px; 
    -webkit-box-shadow:2px 2px 5px #999; 
    padding:16px 10px 40px; 

} 
#formWrap #form { 
border:0px solid #EEE; 
width:720px; 


} 
#form .row { 

border:0; 
display:block; 
line-height:38px; 
overflow:auto; 
padding:24px 0px; 
width:100%; 
} 
#form .row .label { 
font-size:16px; 
font-weight:bold; 
font-family:Arial, Helvetica, sans-serif; 
width:180px; 
text-align:right; 
float:left; 
padding-right:10px; 
margin-right:10px; 



} 
#form.row .input { 
float:left; 
margin-right:10px; 
width:auto; 
} 

.detail{ 
width:260px; 
font-family:Arial, Helvetica, sans-serif; 
font-size:20px; 
padding:7px 8px; 
margin:0; 
display:block; 
border-radius: 5px 5px 5px 5px; 
    background:#E9E9E9; 
border:1px solid #CCC; 
} 
.detail:focus{ 
background-color:#FFF; 
border: 1px solid #999; 
outline: none; 

} 

.message{ 
width:400px; 
max-width:400px; 
height:280px; 
overflow:auto; 
font-family:Arial, Helvetica, sans-serif; 
font-size:20px; 
padding:7px 8px; 
line-height:1em; 
margin:0; 
display:block; 

} 

#form .row .context { 
color:#000; 
font-size:16px; 
line-height:14px; 
font-family:Arial, Helvetica, sans-serif; 
margin-left:5px; 

} 
#formWrap #form #submit { 
font-family:Arial, Helvetica, sans-serif; 
margin-top:25px; 
margin-left:120px; 
color:#000; 
font-size:16px; 
text-shadow:1px 1px 1px #999; 
padding:10px; 
width:150px; 
height:40px; 

} 
span.error{ 
color:#000; 
display:block; 
font-family:Arial, Helvetica, sans-serif; 
background-image:url(file:///C|/wamp/www/ContactForm/images/x.png); 
background-repeat:no-repeat; 
background-position:left 6px; 
padding-left:25px; 


} 

所以,當我運行與Python谷歌AppEngine上的項目,我不能在頁面上看到我的風格。

什麼問題?

+1

你的瀏覽器說什麼?它嘗試加載的CSS?你有404嗎?是不是你認爲應該的路徑? – Thilo 2012-02-22 07:54:23

+0

這是否也發生在開發服務器上,或僅在生產中?你可以分享你已經部署你的應用程序的網址嗎? – proppy 2012-02-22 12:40:02

+0

這可能是一個老問題,但我用這個[溶液] [1] [1]:http://stackoverflow.com/a/31591467/1665739 – smoothBlue 2015-07-23 15:17:46

回答

16

從文檔:

URL handler path patterns are tested in the order they appear in app.yaml 

的問題與您app.yaml所有的URL映射到main.py,所以從來沒有達到你的靜態處理程序。

所以你app.yaml應該是這樣的:這裏的CSS靜態處理器上市之前應用處理

application: paymentgateway 
version: 1 
runtime: python 
api_version: 1 

handlers: 

- url: /css 
    static_dir: css 

- url: .* 
    script: main.py 

注意。

0

如果您僅在使用chrome或safari時看到此問題,您可能會面臨同樣的問題,這是AppEngine中作爲css文件的內容類型返回null的錯誤。升級到1.6.2.1解決了我的問題。