/hobbies/处的TemplateDoesNotExist(已解决) [英] TemplateDoesNotExist at /hobbies/ (solved)

查看:55
本文介绍了/hobbies/处的TemplateDoesNotExist(已解决)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是我上一个问题的续集-不是"hobbieswithCSS.html"的反向成立."hobbieswithCSS.html"不是有效的视图函数或模式名称

This question is the sequel of my previous question - Reverse for 'hobbieswithCSS.html' not found. 'hobbieswithCSS.html' is not a valid view function or pattern name

我已经从一个错误(在上一个问题的标题中)移到了另一个(在此问题的标题中),但是希望这个错误不会那么难解决.

I have moved from one error (in the title of previous question) to another, (in the title of this question) but hopefully this one will not be that much difficult to solve.

我的主页上有这个锚标签-

I have this anchor tag on my homepage -

<a href="{% url 'hobbieswithCSS' %}">My Hobbies</a>

我的views.py文件中有此视图-

I have this view in my views.py file -

def hobbieswithCSS(request):
    return render(request,'hobbieswithCSS.html')

这些是我的网址模式-

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^admin/', admin.site.urls),
    url(r'^basic_app/',include('basic_app.urls')),
    url(r'^logout/$',views.user_logout,name='logout'),
    url(r'^hobbies/$', views.hobbieswithCSS, name='hobbieswithCSS'),
]

有人可以帮我吗?提前非常感谢您.

Can anyone help me please? Thank You very much in advance.

我的问题是在hobbieswithCSS.html文件中的模板标签中,我有这行代码的地方-

My problem was in the template tag in the hobbieswithCSS.html file, where I had this line of code -

{% extends 'base.html' %}

我需要将其更改为-

{% extends 'basic_app/base.html' %}

这已经解决了我的问题,但是感谢您为我提供的帮助.我很感激.

And that has solved my problem, but thanks for Your efforts to help me. I appreciate it.

推荐答案

这些可以肯定地解决它.

these will solve it for sure.

1.如果您通过模板目录中的应用名称将模板保存在单独的模板中,则必须将子文件夹的名称放在模板名称之前,例如 hobbies/hobbieswithCSS.html .2.在项目和模板的 settings.py 中设置模板目录的根.

1.if your saved your templates in a separate templates by app name in templates directory you have to put the name of the sub-folder before the name of the template like this hobbies/hobbieswithCSS.html . 2. set the root of the template directory in your settings.py for project and templates.

BASE_DIR = Path(__file__).resolve().parent.parent

TEMPLATE_DIRS = (
os.path.join(SETTINGS_PATH, 'templates'),
)

还要查看 Django TemplateDoesNotExist吗?

这篇关于/hobbies/处的TemplateDoesNotExist(已解决)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆