TemplateDoesNotExist 在 / index.html
TemplateDoesNotExist at / index.html
我的 Django 项目有一些问题。
我刚开始使用 Django 制作 Web 应用程序。请帮助我。
所以,
这是我的目录路径,
-lullabyluna
----app_index
------------admin.py
------------index.html
------------__init__.py
------------migtations
------------models.py
------------tests.py
------------views.py
----index.html(I wonder this files path.)
----lullabyluna
------------__init__.py
------------settings.py
------------url.py
------------wsgi.py
----manage.py
----static
我的 settings.py 文件包括:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app_index',
)
这是我的 url.py 文件
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('app_index.views',
# Examples:
url(r'^
最后这是我的 app_index/views.py
from django.template import RequestContext
from django.shortcuts import render_to_response
def home(request):
return render_to_response('index.html',{},context_instance=RequestContext(request))
所以,我想知道正确的 "index.html" 文件路径在哪里。
, 'home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
最后这是我的 app_index/views.py
from django.template import RequestContext
from django.shortcuts import render_to_response
def home(request):
return render_to_response('index.html',{},context_instance=RequestContext(request))
所以,我想知道正确的 "index.html" 文件路径在哪里。
将此添加到 settings.py
TEMPLATE_DIRS = (
PROJECT_PATH
)
(或)
将您的 index.html 移动到模板文件夹并执行此操作,
TEMPLATE_DIRS = (
PROJECT_PATH + '/templates/',
)
在 pythonwhere.com 中,您需要在 settings.py
中执行此操作
'DIRS': ['/home/your_user_name/your_project/templates'],
在此处输入代码 lullabyluna ..................... 将您的模板(index.html、home.html 等)放在这里,同时将您的静态文件夹放在这里
现在你在 inside index {% load static%} 之后得到你的索引和静态文件
html {% block content %} 和 {% endblock %} 结束
现在你的页面是动态的
我想,问题可能出在'app_index/views.py'。
你要做的是,在 app 文件夹中创建一个模板文件夹 (app_index)。
在模板文件夹中,创建另一个名为(app_index)的文件夹,然后将 index.html 文件放在这里。
在你这样做之后,在你的 app_index/views.py 中,
改变这个;
" return render_to_response('index.html',{},context_instance=RequestContext(请求)) "
to;
return render_to_response('app_index/index.html',{},context_instance=RequestContext(request))
如果其他一切都没有问题,希望它对你有用。
from django.template import RequestContext
from django.shortcuts import render_to_response
def home(request):
return render_to_response('index.html',{},context_instance=RequestContext(request))
您缺少指向应用程序索引的路径。而不是上面,应该是
def home(request):
return render_to_response('**app_name/**index.html',{},context_instance=RequestContext(request))
在主项目文件夹的 'settings.py' 中提及您的应用程序名称:
INSTALLED_APPS = [
'Your_AppName',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
我已经用 render_to_response 做了很多尝试,但请注意 django 仍然不使用 render_to_response。
使用 render 而不是 render_to_response
所以,
在文件夹 {The_name_of_the_Project} 中,去编辑 settings.py
在 TEMPLATES 中,用包含静态 html 文件的文件夹路径填充 DIRS。
如果 .html 文件存在于您的 {The_name_of_the_Project} 文件夹中,则路径如下所示:'/home/your_username/The_name_of_the_Project/'.
如果 {The_name_of_the_Project} 文件夹中包含静态 .html 文件,那么 DIRS 必须如下所示:DIRS=['/home/your_username/your_project_name/']
我的 Django 项目有一些问题。
我刚开始使用 Django 制作 Web 应用程序。请帮助我。
所以,
这是我的目录路径,
-lullabyluna
----app_index
------------admin.py
------------index.html
------------__init__.py
------------migtations
------------models.py
------------tests.py
------------views.py
----index.html(I wonder this files path.)
----lullabyluna
------------__init__.py
------------settings.py
------------url.py
------------wsgi.py
----manage.py
----static
我的 settings.py 文件包括:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app_index',
)
这是我的 url.py 文件
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('app_index.views',
# Examples:
url(r'^
最后这是我的 app_index/views.py
from django.template import RequestContext
from django.shortcuts import render_to_response
def home(request):
return render_to_response('index.html',{},context_instance=RequestContext(request))
所以,我想知道正确的 "index.html" 文件路径在哪里。
, 'home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), )最后这是我的 app_index/views.py
from django.template import RequestContext
from django.shortcuts import render_to_response
def home(request):
return render_to_response('index.html',{},context_instance=RequestContext(request))
所以,我想知道正确的 "index.html" 文件路径在哪里。
将此添加到 settings.py
TEMPLATE_DIRS = (
PROJECT_PATH
)
(或) 将您的 index.html 移动到模板文件夹并执行此操作,
TEMPLATE_DIRS = (
PROJECT_PATH + '/templates/',
)
在 pythonwhere.com 中,您需要在 settings.py
中执行此操作'DIRS': ['/home/your_user_name/your_project/templates'],
在此处输入代码 lullabyluna ..................... 将您的模板(index.html、home.html 等)放在这里,同时将您的静态文件夹放在这里 现在你在 inside index {% load static%} 之后得到你的索引和静态文件 html {% block content %} 和 {% endblock %} 结束 现在你的页面是动态的
我想,问题可能出在'app_index/views.py'。 你要做的是,在 app 文件夹中创建一个模板文件夹 (app_index)。 在模板文件夹中,创建另一个名为(app_index)的文件夹,然后将 index.html 文件放在这里。 在你这样做之后,在你的 app_index/views.py 中, 改变这个; " return render_to_response('index.html',{},context_instance=RequestContext(请求)) "
to;
return render_to_response('app_index/index.html',{},context_instance=RequestContext(request))
如果其他一切都没有问题,希望它对你有用。
from django.template import RequestContext
from django.shortcuts import render_to_response
def home(request):
return render_to_response('index.html',{},context_instance=RequestContext(request))
您缺少指向应用程序索引的路径。而不是上面,应该是
def home(request):
return render_to_response('**app_name/**index.html',{},context_instance=RequestContext(request))
在主项目文件夹的 'settings.py' 中提及您的应用程序名称:
INSTALLED_APPS = [
'Your_AppName',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
我已经用 render_to_response 做了很多尝试,但请注意 django 仍然不使用 render_to_response。 使用 render 而不是 render_to_response
所以,
在文件夹 {The_name_of_the_Project} 中,去编辑 settings.py
在 TEMPLATES 中,用包含静态 html 文件的文件夹路径填充 DIRS。 如果 .html 文件存在于您的 {The_name_of_the_Project} 文件夹中,则路径如下所示:'/home/your_username/The_name_of_the_Project/'.
如果 {The_name_of_the_Project} 文件夹中包含静态 .html 文件,那么 DIRS 必须如下所示:DIRS=['/home/your_username/your_project_name/']