在IIS上部署我的Django网站后,我收到如下错误:
TemplateDoesNotExist at /test/new_site/list/
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.app_directories.Loader: D:\workspace\One_Site_Project\env_one_site_37\lib\site-packages\django\contrib\admin\templates\test\new_site_list.html (Source does not exist)
django.template.loaders.app_directories.Loader: D:\workspace\One_Site_Project\env_one_site_37\lib\site-packages\django\contrib\auth\templates\test\new_site_list.html (Source does not exist)
django.template.loaders.app_directories.Loader: D:\workspace\One_Site_Project\env_one_site_37\lib\site-packages\rest_framework\templates\test\new_site_list.html (Source does not exist)我不知道为什么IIS要在virtualenv目录中搜索我的模板文件。
我的视图渲染代码是,
@method_decorator(csrf_exempt, name='dispatch')
class NewSiteListUpdate(View):
"""
This class is used to list all the new site activity, also update an activity
"""
def get(self, request, *args, **kwargs):
"""
List all the activity info or a particular activity info
:param request:
:param args:
:param kwargs:
:return:
"""
if request.user.is_staff:
self.data = ActivityInformation.objects.all()
self.radius = 11111
return render(request, 'test/new_site_list.html', {'data': self.data})下面是我在settings.py文件中的模板设置,
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR + '/template/'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
# 'builtins': [
# 'src.huawei.templatetags.custom_tags'
# ],
'libraries':{
'custom_tags': 'templatetags.custom_tags',
},
},
},
]下面是我的项目结构,

这在我的本地系统中工作得很好。我也尝试将模板文件夹添加到虚拟目录中,但没有使用,仍然显示相同的错误。为了在this上设置我的应用程序,我遵循了IIS。
我使用的是python 3.7和IIS 8.5
我花了两天的时间来解决这个问题,但我没有找到任何与此相关的解决方案。
任何帮助都将不胜感激。提前谢谢。
发布于 2019-06-17 20:57:47
我认为您必须修改代码中的某些部分
settings.py
尝试更改模板‘DIRS’:BASE_DIR +‘//’,to 'DIRS'=os.path.join(BASE_DIR,'template'),
渲染函数生成的路径是:../template/huawei/new_site_list.html,但是在你的项目结构中,你没有一个views.py views.py。你必须这样写:return render(request,'test/new_site_list.html',{'data':self.data})
https://stackoverflow.com/questions/56629694
复制相似问题