认为问题出在你/的道路上。删除,/因为
static与处于同一级别
views.py。
我建议将
settings.py水平设置为
views.py或许多Flask用户喜欢使用,
__init__.py但我不喜欢。
application_top/ application/ static/ english_words.txt templates/ main.html urls.py views.py settings.py runserver.py
如果这是你要设置的方式,请尝试以下 *** 作:
#settings.pyimport os# __file__ refers to the file settings.py APP_ROOT = os.path.dirname(os.path.abspath(__file__)) # refers to application_topAPP_STATIC = os.path.join(APP_ROOT, 'static')
现在,你可以轻松执行以下 *** 作:
import osfrom settings import APP_STATICwith open(os.path.join(APP_STATIC, 'english_words.txt')) as f: f.read()
根据需要调整路径和级别。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)