【问题标题】:CSS Style Not Populating CorrectlyCSS 样式未正确填充
【发布时间】:2017-02-21 18:25:36
【问题描述】:

我正在构建一个烧瓶应用程序,我试图让它看起来更好,但颜色没有按预期填充。知道为什么颜色不能正确通过。 (我在 IE 和 Chrome 浏览过,都是一样的)。

文件夹结构是(还有其他 HTML 文件,但它们对于重新创建问题并不重要):

main/site_tables.py
main/templates/view.html
main/static/style.css

python 代码(site_tables.py)是:

#Import various necessary packages
from flask import render_template, Flask, request
import pandas
from pandas.tseries.holiday import USFederalHolidayCalendar
import datetime
import urllib2
import os.path

#Start App from Flask
app = Flask(__name__)

#Set IP Address and Port for outputting web address
out_IP_address = "0.0.0.0"
out_port = 5000

#Set location for original files being read in and edit file locations
#Kept seperate for audit reasons
origLoc = "C:/Orig"
editLoc = "C:/Edit"

#Set name of files prefix
fileName = "Rand_Calls"

#Define holidays for long period of time
cal = USFederalHolidayCalendar()
holidays = cal.holidays(start='2017-01-01', end='2030-12-31').to_pydatetime()

#Set first empty link - tables
@app.route("/tables/")
#Set dynamically populated links tables/date where date is formatted YYYYMMDD
@app.route("/tables/<date>",methods=['GET', 'POST'])
def j_show_html(date):
    #date provided by webaddress for example: date = "20170214"
    #Format date to datetime
    date2 = datetime.datetime.strptime(date,"%Y%m%d")
    if request.method == "GET":
        #If date hasn't occured; display why missing
        if date2 > datetime.datetime.today()  - datetime.timedelta(days=2):
            return render_template('future.html',
            labels = urllib2.unquote(date.encode('ascii','ignore')))
        #If date was a holiday; display why missing
        elif date2 in holidays:
            return render_template('holiday.html',
            labels = urllib2.unquote(date.encode('ascii','ignore')))
        #If date was a weekend; display why missing
        elif date2.weekday() in (5,6):
            return render_template('weekend.html',
            labels = urllib2.unquote(date.encode('ascii','ignore')))
        #Load report; if not edited before then from original location
        else:
            if os.path.isfile(editLoc+"/"+fileName+"_"+date+"_"+date+".xlsx"):
                report = pandas.read_excel(editLoc+"/"+fileName+"_"+date+"_"+date+".xlsx")
            else:
                report = pandas.read_excel(origLoc+"/"+fileName+"_"+date+"_"+date+".xlsx")
            return render_template('view.html',
            tables=[report.to_html(index=False)],
#            titles = ['na'],
            labels = urllib2.unquote(date.encode('ascii','ignore')))

#Call the app
if __name__ == "__main__":
    app.run(host=out_IP_address,port=out_port,debug=True)

HTML 文件 (view.html) 是:

<!-- Jinja2 code for table page creation -->
<!doctype html>
<title>{{labels}}</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
<div class=page contenteditable="">
  <h1>QA_Report_{{labels}}</h1>
  {% for table in tables %}
    {{ table|safe }}
  {% endfor %}
</div>

CSS文件是(style.css)是:

body            { font-family: sans-serif;}
a, h1, h2       { color: #d03027; } /*Color = Specific Red */
h1, h2          { margin: 0; }
h1              { border-bottom: 2px solid #ceccd0; } /*Color - Light Grey*/
h2              { font-size: 1.2em; }

table.dataframe, .dataframe th, .dataframe td 
{
  border: none;
  border-bottom: 1px solid #ceccd0; /*Color = Light Grey*/
  border-collapse: collapse;
  text-align:left;
  padding: 10px;
  margin-bottom: 40px;
  font-size: 0.9em;
}

tr:nth-child(odd)      { background-color:#ffffff; } /*Color = White            */
tr:nth-child(even)  { background-color:#004977; color:#ffffff; } /*Color = Specific Blue */
tr:hover            { background-color:#d03027; } /*Color = Specific Red  */

【问题讨论】:

  • 它应该是什么样子的?
  • 相同,但在 CSS 中指定的颜色应该会产生不同的视觉外观。我已经对 CSS 进行了评论,以显示大致应该是什么颜色。

标签: python html css flask jinja2


【解决方案1】:

解决了这个问题。

网页正在被缓存。我清除了浏览器历史记录并且更改通过了。 (使用 Ctrl+Shift+R 重新加载页面也将允许进行新的更改)。

将此作为答案发布,以防万一遇到相同问题的人有所帮助。

【讨论】:

  • 也可能是您的 style.css 没有被加载。将来,如果您发布项目的结构以及每个文件的位置,将会很有帮助。此外,如果您在代码 sn-ps 上指定文件名,对人们来说会更容易。
  • 谢谢。交替的行颜色提示我正在加载某些内容,但我看到了您的观点并更新了问题。
猜你喜欢
  • 2014-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多