[英]Templates Work on Localhost but Not Production / Live Server
I have a setup to recognize the static files and template files at the top level (above the apps folders) like so: 我有一个设置可以识别顶级(在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/',
)
It works fine in the local environment, but online I get this: 它在本地环境中运行良好,但是在网上我得到了:
TemplateDoesNotExist at /
home.html
What could be causing this inconsistency? 是什么导致这种不一致?
Try this... 尝试这个...
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
If it doesn't work, declare your template path in a variable like 如果不起作用,请在变量中声明模板路径,例如
template_path = /path/to/template
TEMPLATE_PATH_DIRS = (
template_path + '/templates',
)
TEMPLATE_DIRS = TEMPLATE_PATH_DIRS
It will work, try it. 它将起作用,尝试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.