我在我的mac上使用Flask(python包),当我第一次写我的css时显示确定.但是,当我更新它并尝试检查它时,我只看到第一个CSS样式.我尝试重新启动终端,以及重新安装Flask.有什么建议?谢谢.继承人HTML:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<header>
<div class="header"></div>
<div class="logo">
<center><img src="/static/img/p_logo.png" alt="pic"/></center>
</div>
</header>
<div class="container">
{% block content %}
{% endblock %}
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
还有CSS:
* {
font-family: "Times New Roman", Times, serif;
}
header {
background-color: #000000;
width: 100%;
height: 7px;
}
Run Code Online (Sandbox Code Playgroud) 我试过用这个
@app.after_request
def add_header(response):
response.headers['Cache-Control'] = 'max-age=300'
return response
Run Code Online (Sandbox Code Playgroud)
但这会导致出现重复的Cache-Control标头.我只想要max-age = 300,而不是max-age = 1209600行!
$ curl -I http://my.url.here/
HTTP/1.1 200 OK
Date: Wed, 16 Apr 2014 14:24:22 GMT
Server: Apache
Cache-Control: max-age=300
Content-Length: 107993
Cache-Control: max-age=1209600
Expires: Wed, 30 Apr 2014 14:24:22 GMT
Content-Type: text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud) 我有一个Flask应用程序,其中使用一个Flask route
服务器会创建一个csv文件并将其保存到服务器。使用客户端页面上的生成按钮,将route
触发另一个Flask 以获取最新文件,将其移动到tmp文件夹,然后使用将文件发送给用户send_file
。
现在,当我第一次运行该过程并下载文件时,所有操作都按预期进行。但是,第二次运行该过程时,它将为我提供旧的CSV而不是新生成的CSV。这一直持续到我点击浏览器上的刷新按钮。
以下是我的应用程序代码:
from flask import Flask, render_template, flash, redirect, request, url_for, Response, send_file
import os
import time
import shutil
import glob
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/downloadcsv')
def downloadcsv():
current = os.getcwd()
try:
list = glob.glob('{}/*.csv'.format(current))
except:
print('No file found')
basename = os.path.basename(os.path.normpath(max(list, key=os.path.getctime)))
shutil.move(basename, './tmp/{}'.format(basename))
return send_file('./tmp/{}'.format(basename), as_attachment=True)
Run Code Online (Sandbox Code Playgroud)
如果需要,以下是“生成”下载按钮的JS代码:
var download = '<div id="downloadsection" class="container-contact100-form-btn"><a href="/downloadcsv"><button id="download" class="contact100-form-btn"> <span>DOWNLOAD CSV</span></button></a></div>';
Run Code Online (Sandbox Code Playgroud)
如果我使下载过程变得过于复杂,也请让我知道...
谢谢!!