Django找不到我的模板

时间:2018-03-14 19:25:19

标签: django django-templates django-views web-development-server

我发现了很多像这样的问题,但没有人解决这个问题。

当我访问网址时

http://localhost:8000/catalog/book/88a26558-d636-44c8-8831-242d98fa6d80/renew/

由此urls.py路径处理:

path('book/<uuid:pk>/renew/', views.renew_book_librarian, name='renew-book-librarian'),

比我最后的观点还给出了这个:

I have a view that returns this:

 return render(request,'catalog/book_renew_librarian.html', {'form': form, 'bookinst':book_inst}) 

但是我得到了模板错误:

TemplateDoesNotExist at /catalog/book/88a26558-d636-44c8-8831-242d98fa6d80/renew/
catalog/book_renew_librarian.html
Request Method: GET
Request URL:    http://localhost:8000/catalog/book/88a26558-d636-44c8-8831-242d98fa6d80/renew/
Django Version: 2.0.3
Exception Type: TemplateDoesNotExist
Exception Value:    
catalog/book_renew_librarian.html
Exception Location: C:\Users\Araujo\AppData\Local\Programs\Python\Python36\lib\site-packages\django\template\loader.py in get_template, line 19
Python Executable:  C:\Users\Araujo\AppData\Local\Programs\Python\Python36\python.exe
Python Version: 3.6.4
Python Path:    
['C:\\Users\\Araujo\\Desktop\\first_django\\locallibrary',
 'C:\\Users\\Araujo\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
 'C:\\Users\\Araujo\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
 'C:\\Users\\Araujo\\AppData\\Local\\Programs\\Python\\Python36\\lib',
 'C:\\Users\\Araujo\\AppData\\Local\\Programs\\Python\\Python36',
 'C:\\Users\\Araujo\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']
Server time:    Wed, 14 Mar 2018 19:19:10 +0000

但我在

中有模板
\catalog\templates\book_renew_librarian.html

如何解决?

1 个答案:

答案 0 :(得分:2)

您指定的路径的目录结构应为:

ProjectFolder
    -projectfolder
    -catalog
        -templates
            -catalog
                book_renew_librarian.html
    -manage.py