2015-07-18 44 views
0

我知道我愚蠢,因为谷歌没有返回任何结果。我对计算机知之甚少,但0x00000blah看起来像一些内存地址。经过几次刷新后,这个数字会发生变化。Django奇怪的错误将我的模板名称变成0x000000000461A128

环境 Django的1.8,Python的3.4,铬,Win7的

预期的行为 我想去../accounts/login/也被称为我的网址url(r'^login/$', 'django.contrib.auth.views.login', name='loginHandle')在用户名输入,密码,如果是注册重定向到../accounts/profile它应该呈现模板profile.html,它会说类似Hello {{ username }} !。相反,我得到这个错误

TemplateDoesNotExist在/帐号/资料/

在0x0000000004D0E400

views.py

def profile(request): 
    profileTemplate = loader.get_template('registration/profile.html') 
    return render(request, profileTemplate, { 
     'Kitty': 10, 
    }) 
django.template.backends.django.Template对象

回溯

Using loader django.template.loaders.filesystem.Loader: 
D:\users\kitty\python\firstdjangosite\templates\<django.template.backends.django.Template object at 0x0000000004D0E400> (File does not exist) 
Using loader django.template.loaders.app_directories.Loader: 
D:\Users\kitty\Python\lib\site-packages\django\contrib\admin\templates\<django.template.backends.django.Template object at 0x0000000004D0E400> (File does not exist) 
D:\Users\kitty\Python\lib\site-packages\django\contrib\auth\templates\<django.template.backends.django.Template object at 0x0000000004D0E400> (File does not exist) 
D:\users\kitty\python\firstdjangosite\polls\templates\<django.template.backends.django.Template object at 0x0000000004D0E400> (File does not exist) 
D:\users\kitty\python\firstdjangosite\login\templates\<django.template.backends.django.Template object at 0x0000000004D0E400> (File does not exist) 
D:\users\kitty\python\firstdjangosite\accounts\templates\<django.template.backends.django.Template object at 0x0000000004D0E400> (File does not exist) 

路径详细信息

D:\Users\Kitty\Python\FirstDjangoSite\accounts\templates>dir /s /b /o:gn 
accounts 
registration 
accounts\index.html 
accounts\invalid.html 
accounts\loggedin.html 
accounts\logout.html 
registration\login.html 
registration\profile.html 

我已经做了装载机和之前渲染和他们很好地工作。举例来说,如果我改变profileTemplate到不存在的 '注册/的helloworld.html' 它说

TemplateDoesNotExist在/帐号/资料/

注册/的helloworld.html

感谢您的时间,请帮助我很困惑

回答

3

render快捷方式需要模板名称。

def profile(request): 
    return render(request, 'registration/profile.html', { 
     'Kitty': 10, 
    }) 

令人惊讶的错误消息是因为您传递了一个加载的模板而不是模板名称。 django.template.backends.django.Template object at 0x0000000004D0E400profileTemplaterepr()

+0

感谢您的快速响应,这是有道理的和有效的!干杯(当SO允许时会接受) –