[英]TemplateDoesNotExist Error in Pythonanywhere
I wanna know where django search for index.html我想知道 django 在哪里搜索 index.html
Setting.py
设置.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'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',
],
},
},
]
views.py
视图.py
def index(request):
return render(request, 'index.html', {})
Django will look in the templates directory, that's if you created a folder called templates and if you have a file named index.html in the templates folder. Django 将查看模板目录,如果您创建了一个名为 templates 的文件夹,并且在模板文件夹中有一个名为 index.html 的文件。 For some reason I feel like the reason why you are asking this question is because you can not get your template to render when you run the server, am I correct?
出于某种原因,我觉得您问这个问题的原因是因为您在运行服务器时无法渲染模板,对吗? Please get back to me and I can do my best to fill you in so you can get your project working.
请回复我,我会尽力为您填写信息,以便您的项目能够正常运行。
您可以轻松解决这个问题:如果您的项目目录,manage.py 所在的名称是“RalphPortfolio”,您需要在settings.py 中进行以下更正:
'DIRS': ['RalphPortfolio/templates'],
add the full path to the template dirs for example if your path is /home/some_url/your_project/templates例如,如果您的路径是 /home/some_url/your_project/templates,请添加模板目录的完整路径
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['/home/some_url/your_project_name/templates'],
'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',
],
},
},
]
it's because the path is not clear well and it will not find it.那是因为路径不是很清楚,它不会找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.