首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IIS+Django上不存在模板

IIS+Django上不存在模板
EN

Stack Overflow用户
提问于 2019-06-17 18:45:06
回答 1查看 269关注 0票数 0

在IIS上部署我的Django网站后,我收到如下错误:

代码语言:javascript
复制
 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目录中搜索我的模板文件。

我的视图渲染代码是,

代码语言:javascript
复制
@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文件中的模板设置,

代码语言:javascript
复制
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

我花了两天的时间来解决这个问题,但我没有找到任何与此相关的解决方案。

任何帮助都将不胜感激。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 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})

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56629694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档