English 中文(简体)
Django, 无法找到模板
原标题:Django, template cannot be found

由于某种原因,我创建的网站应用程序无法找到模板。 我也试图将html的档案放在几个不同的地点,但它仍然胜诉。 截至现在,我已在以下地点安置了我的模板主任:<编码>C:xampphtdocsdjango_proj emplate。 其他人不知道问题是什么。

我在这个项目中还有另一个网络应用程序。 模型和观点几乎相同,但网络应用可以找到模板。

/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)

/webapp/views.py

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 )

/webapp/urls.py

from django.conf.urls.defaults import *

import views

urlpatterns = patterns(  ,

    url(r ^list/$ , views.profile_list, name= profile_list ),
)

/urls.py

from django.conf.urls import *

    urlpatterns = patterns(  ,

         (r ^webapp/ , include( webapp.urls )),
    )

<>strong>/templates/webapp/list.html>

<html>
  <body>
  Test
  </body>
</html>

错误信息

TemplateDoesNotExist at /webapp/list/

/webapp/list.html

Request Method:     GET
Request URL:    http://localhost:8000/webapp/list/
Django Version:     1.4 pre-alpha
Exception Type:     TemplateDoesNotExist
Exception Value:    

/webapp/list.html

Exception Location:     c:	oolspython27libsite-packagesdjango	emplateloader.py in find_template, line 138
Python Executable:  c:	oolspython27python.exe
Python Version:     2.7.2
Python Path:    

[ C:\xampp\htdocs\webnotes ,
  c:\tools\python27\lib\site-packages\pip-1.0.2-py2.7.egg ,
  C:\Windows\system32\python27.zip ,
  c:\tools\python27\DLLs ,
  c:\tools\python27\lib ,
  c:\tools\python27\lib\plat-win ,
  c:\tools\python27\lib\lib-tk ,
  c:\tools\python27 ,
  c:\tools\python27\lib\site-packages ]

Server time:    Thu, 12 Jan 2012 19:33:48 +0100
Template-loader postmortem

Django tried loading these templates, in this order:

    Using loader django.template.loaders.filesystem.Loader:
    Using loader django.template.loaders.app_directories.Loader: 
最佳回答

页: 1 使它成为一条相对途径:webapp/list.html 因此,os.path.join (.)处理按原样划定的道路。

Try this:

def profile_list(request):
    return object_list(request,
        queryset=Profile.objects.all(),
        template_name= webapp/list.html , # removed slash here.
        template_object_name= profiles )
问题回答

Try 纽约总部change your url pattern on /webapp/urls.py from:

url(r ^list/$ , views.profile_list, name= profile_list ),

纽约总部

url(r ^webapp/list/$ , views.profile_list, name= profile_list ),




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签