Django,找不到模板
由于某些原因,我创建的webapp找不到模板。我还试图将html文件放在几个不同的位置,但它仍然找不到。到目前为止,我已将模板控制器放置在以下位置Django,找不到模板,django,django-templates,Django,Django Templates,由于某些原因,我创建的webapp找不到模板。我还试图将html文件放在几个不同的位置,但它仍然找不到。到目前为止,我已将模板控制器放置在以下位置C:\xampp\htdocs\django\u proj\templates\。其他人知道问题可能是什么吗 我在这个django项目中有另一个Web应用程序。模型和视图看起来几乎相同,但是webapp可以找到模板 /webapp/models.py from django.db import models class Profile(models.
C:\xampp\htdocs\django\u proj\templates\
。其他人知道问题可能是什么吗
我在这个django项目中有另一个Web应用程序。模型和视图看起来几乎相同,但是webapp可以找到模板
/webapp/models.py
from django.db import models
class Profile(models.Model):
name = models.CharField(max_length=255)
age = models.IntegerField()
added_at = models.DateTimeField(auto_now_add=True)
from django.views.generic.list_detail import object_list
from models import Profile
def profile_list(request):
return object_list(request,
queryset=Profile.objects.all(),
template_name='/webapp/list.html',
template_object_name='profiles')
from django.conf.urls.defaults import *
import views
urlpatterns = patterns('',
url(r'^list/$', views.profile_list, name='profile_list'),
)
from django.conf.urls import *
urlpatterns = patterns('',
(r'^webapp/', include('webapp.urls')),
)
/webapp/views.py
from django.db import models
class Profile(models.Model):
name = models.CharField(max_length=255)
age = models.IntegerField()
added_at = models.DateTimeField(auto_now_add=True)
from django.views.generic.list_detail import object_list
from models import Profile
def profile_list(request):
return object_list(request,
queryset=Profile.objects.all(),
template_name='/webapp/list.html',
template_object_name='profiles')
from django.conf.urls.defaults import *
import views
urlpatterns = patterns('',
url(r'^list/$', views.profile_list, name='profile_list'),
)
from django.conf.urls import *
urlpatterns = patterns('',
(r'^webapp/', include('webapp.urls')),
)
/webapp/url.py
from django.db import models
class Profile(models.Model):
name = models.CharField(max_length=255)
age = models.IntegerField()
added_at = models.DateTimeField(auto_now_add=True)
from django.views.generic.list_detail import object_list
from models import Profile
def profile_list(request):
return object_list(request,
queryset=Profile.objects.all(),
template_name='/webapp/list.html',
template_object_name='profiles')
from django.conf.urls.defaults import *
import views
urlpatterns = patterns('',
url(r'^list/$', views.profile_list, name='profile_list'),
)
from django.conf.urls import *
urlpatterns = patterns('',
(r'^webapp/', include('webapp.urls')),
)
/url.py
from django.db import models
class Profile(models.Model):
name = models.CharField(max_length=255)
age = models.IntegerField()
added_at = models.DateTimeField(auto_now_add=True)
from django.views.generic.list_detail import object_list
from models import Profile
def profile_list(request):
return object_list(request,
queryset=Profile.objects.all(),
template_name='/webapp/list.html',
template_object_name='profiles')
from django.conf.urls.defaults import *
import views
urlpatterns = patterns('',
url(r'^list/$', views.profile_list, name='profile_list'),
)
from django.conf.urls import *
urlpatterns = patterns('',
(r'^webapp/', include('webapp.urls')),
)
/templates/webapp/list.html
<html>
<body>
Test
</body>
</html>
尝试从以下位置更改/webapp/url.py上的url模式:
url(r'^list/$', views.profile_list, name='profile_list'),
到
尝试从以下位置更改/webapp/url.py上的url模式:
url(r'^list/$', views.profile_list, name='profile_list'),
到
您的模板名称包含一个默认路径
/webapp/list.html
。尝试将其设置为相对路径webapp/list.html
,以便os.path.join(.)
按预期处理路径连接
试试这个:
def profile_list(request):
return object_list(request,
queryset=Profile.objects.all(),
template_name='webapp/list.html', # removed slash here.
template_object_name='profiles')
您的模板名称包含一个默认路径
/webapp/list.html
。尝试将其设置为相对路径webapp/list.html
,以便os.path.join(.)
按预期处理路径连接
试试这个:
def profile_list(request):
return object_list(request,
queryset=Profile.objects.all(),
template_name='webapp/list.html', # removed slash here.
template_object_name='profiles')
您是否得到一个带有“模板未找到错误”的错误页面?你能发布错误消息吗?它通常包含Django查找模板的路径列表。此外,任何相关的Django设置都会有所帮助。您是否会看到带有“模板未找到错误”的错误页面?你能发布错误消息吗?它通常包含Django查找模板的路径列表。此外,任何相关的Django设置都会有所帮助。但是我已经在
/url.py
中添加了该部分,因此将其添加到/webapp/url.py
将导致它找不到url。但是我已经在/url.py
中添加了该部分,因此将其添加到/webapp/url.py
将导致它找不到url。啊,这么小的事情。谢谢救了我一天:)啊,这么小的一件事。谢谢你救了我一天:)