Flask index.py 修改未生效
我正在开发一个比较简单的网页应用,使用的是Flask框架,现在想把它部署到Digital Ocean的虚拟专用服务器(VPS)上。我已经用apache2和WSGI把它运行起来了。这是我的代码仓库。我对运维方面的知识不太了解,所以不知道为什么现在这个不太好使。
在 /var/www/VAWomensHealth/
这个目录下,我有一个文件夹,里面放着Flask应用,叫做 VAWomensHealth
,还有一个 VAWomensHealth.wsgi
文件,内容是这样的:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/VAWomensHealth/")
from VAWomensHealth import app as application
#from app import app as application
application.secret_key = 'Add your secret key'
我的 index.py
文件内容是这样的:
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/feeds')
def feeds():
return render_template('feeds.html')
if __name__ == '__main__':
app.run(debug=True)
而在 /etc/apache2/sites-enabled/
目录下,我的 VAWomensHealth.conf
文件内容是这样的:
<VirtualHost *:80>
ServerName bagbot.com
ServerAdmin chris@example.com
WSGIScriptAlias / /var/www/VAWomensHealth/VAWomensHealth.wsgi
WSGIScriptReloading On
<Directory /var/www/VAWomensHealth/VAWomensHealth/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/VAWomensHealth/VAWomensHealth/static
<Directory /var/www/VAWomensHealth/VAWomensHealth/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
所以当我访问这个域名时,主网站能够正常加载。而且当我修改我的静态文件或模板时,这些改动会立即在网站上显示出来。
不过,我对 index.py
文件所做的代码修改似乎没有生效(比如我想让首页加载一个不同的模板)。这让我无法在我的应用中添加其他的路由。
有没有什么建议?
1 个回答
1
对我来说(不过我没法测试),你需要把文件名 index.py
改成 __init__.py
或者你也可以在 wsgi
文件中使用 index
from VAWomensHealth.index import app as application