- error : Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
solution: 将app.py放在当前根目录下,输入pwd就可以知道当前根目录 - NoAppException: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
solution: 在之前的目录下有 .env 或 .flaskenv 文件,删除即可 - socket.error: [Errno 48] Address already in use
solution: 用$ sudo lsof -i:5000 查看进程,然后杀死进程sudo kill #pid。 - flask修改代码后网页无法跟新。跟这里遇到的问题一样
solution: (目前还未被解决!)
有几种可能性:
1)我觉得是虚拟环境安装的问题。pipenv install 要在当前项目目录下安装,也就是说pipfile 和pip.lock都要在当前目录下。而我是在根目录下安装的,项目是根目录下的一个文件夹。
之前在根目录下安装Pipenv启动虚拟环境时是这个:
bash-3.2 . /Users/Huizhi/watchlist/.venv/bin/activate
更新了以后还是没有办法解决。
2)有可能是浏览器缓存的问题。那么,就打开inspect-点右上角3点-settings-选中disable cache就好了。
现在问题好像解决了 - 还是出现了CSS文件没有渲染的问题。
solution:
from datetime import timedelta
# 设置静态文件缓存过期时间
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = timedelta(seconds=1)
也可以这样写:
app.send_file_max_age_default = timedelta(seconds=1)
rel 要写icon。不能自己编!!!
-
SyntaxError: Non-ASCII character '\xe7' in file /Users/Huizhi/watchlist/app.py on line 50, but no encoding declared;
solution: 在文件app.py前面加# -- coding: utf-8 - -
global name 'redirect' is not defined
solution: from flask import redirect
FAIL: test_settings (__main__.WatchlistTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_watchlist.py", line 132, in test_settings
self.assertIn('Invalid input.', data)
AssertionError: 'Invalid input.' not found in u'<!DOCTYPE html>\n<html lang="en">\n <head>\n \n <meta charset="utf-8">\n <meta name = "viewport" content = "width = device-width, initial-scale = 1.0">\n <title>Test\'s Watchlist</title>\n <link rel= "icon" href ="/static/bayern.png">\n <link rel= "stylesheet" href ="/static/style.css" type="text/css">\n \n </head>\n <body>\n <!-- \u63d2\u5230\u9875\u9762\u6807\u9898\u4e0a\u65b9-->\n \n <div class = "alert">Invalid inout.</div>\n \n <h2>\n <img alt= "Porto" class = "porto" src = "/static/images/porto.jpg">\n Test\'s Watchlist\n </h2>\n <nav>\n <ul>\n <li><a href="/">Home</a></li>\n \n <li><a href="/settings">Settings</a></li>\n <li><a href="/logout">Logout</a></li>\n \n </ul>\n </nav>\n \n<h3>Settings</h3>\n<form method = "post">\n Your Name <input type ="text" name ="name" autocomplete="off" required value=\n "Test">\n <input class = "btn" type="submit" name="submit" value="Save">\n</form>\n\n <footer>\n <small>©2018 <a href = "http://helloflask.com/tutotial">helloflask</a></small>\n\n </footer>\n\n\n </body>\n</html>'
解决方法: 我把这一行注释掉了
网友评论