簡體   English   中英

模板可在Localhost上使用,但不能在生產/實時服務器上使用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM