简体   繁体   English

模板可在Localhost上使用,但不能在生产/实时服务器上使用

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

相关问题 Flask:从本地计算机移至生产服务器时的本地主机引用 - Flask: Localhost References When Moving from Local Machine to Production Server 我的 fastapi 应用程序在生产服务器上被压垮了,但也在本地主机上工作 - My fastapi app getting crushed on production server but also working on localhost 如果从我的生产服务器向其他生产服务器发出 httprequest,则会出现连接错误,但它是通过 localhost 完成的 - Getting connection error if made httprequest from my production server to other production server , but its done with localhost 实时服务器上的未知错误,但该模块在本地主机上运行良好 - an unknown error on a live server but the module works very well on localhost 从本地主机金字塔生活 - pyramid from localhost to live 为什么我的 Django 登录可以在开发服务器上运行而不是在生产服务器上运行? - Why does my Django login work on development server but not production server? Django表单不在生产服务器上呈现 - 使用testserver在本地工作正常,并且单元测试在生产服务器上传递 - Django forms not rendering on production server - work fine locally with testserver, and unit tests pass on production server Keras 中的 load_model 在 Flask API 的生产服务器中不起作用 - load_model in Keras does not work in production server with Flask API 带有 CuDNNLSTM 层的 Keras 模型在生产服务器上不起作用 - Keras Model With CuDNNLSTM Layers Doesn't Work on Production Server 为什么 Django/Python 请求在生产服务器上不起作用? - Why Django/Python request doesn't work from production server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM