![](/img/trans.png)
[英]Flask: Localhost References When Moving from Local Machine to Production Server
[英]Templates Work on Localhost but Not Production / Live Server
我有一個設置可以識別頂級(在apps文件夾上方)的靜態文件和模板文件,如下所示:
import os
BASE_DIR = os.path.realpath(os.path.dirname(__file__))
...
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
TEMPLATE_DIRS = (
BASE_DIR + '/templates/',
)
它在本地環境中運行良好,但是在網上我得到了:
TemplateDoesNotExist at /
home.html
是什么導致這種不一致?
嘗試這個...
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
如果不起作用,請在變量中聲明模板路徑,例如
template_path = /path/to/template
TEMPLATE_PATH_DIRS = (
template_path + '/templates',
)
TEMPLATE_DIRS = TEMPLATE_PATH_DIRS
它將起作用,嘗試一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.