Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django test TemplateDoesNotExist

Tags:

python

django

i hava a django pratice like this

│  manage.py
├─accounts
│  │  models.py
│  │  tests.py
│  │  urls.py
│  │  views.py
│  │  __init__.py
│  │
│  └─templates
│      └─accounts
│              detail.html
│              index.html
│              login.html
│              register.html
│
├─my_site
│      settings.py
│      urls.py
│      wsgi.py
│      __init__.py
│
└─templates
        base.html

when i write the test which is also inside django guide, when i test the assertRedirects, the "to" login.html will raise error described below bacause of this:

{% extends "base.html" %}

the error is this:

TemplateDoesNotExist: base.html

in my settings.py, TEMPLATE_DIRS looks like this

TEMPLATE_DIRS = (
    'templates'
)

so is there anyone tell my how to fix this?

like image 871
resume_test Avatar asked Dec 18 '25 01:12

resume_test


1 Answers

add this to your TEMPLATE_DIRS:

import os
TEMPLATE_DIRS = (
    'templates',
    os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\', '/')
)
like image 68
shellbye Avatar answered Dec 20 '25 15:12

shellbye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!