M
M
Millerish2016-05-22 20:12:56
Django
Millerish, 2016-05-22 20:12:56

Django where is the error?

Good time of the day!
I'm learning Django, tell me where the error is:
Error:

TemplateDoesNotExist at /basicviwe/2/
mywiew.html
Request Method: GET
Request URL: 127.0.0.1:8000/basicviwe/2
Django Version: 1.8
Exception Type: TemplateDoesNotExist
Exception Value:
mywiew.html
Exception Location: /home/mk/Documents/ DjangoTest2/myvenv/lib/python3.5/site-packages/django/template/loader.py in get_template, line 46
Python Executable: /home/mk/Documents/DjangoTest2/myvenv/bin/python
Python Version: 3.5.1
Python Path:
['/home/mk/Documents/DjangoTest2',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64- linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/home/mk/Documents/DjangoTest2/myvenv/lib/python3.5/site-packages']

Template folder:
"/home/mk/Documents/DjangoTest2/templates"
settings.py:
DIRNAME = os.path.abspath(os.path.dirname(__file__))
TEMPLATE_DIRS = (
os.path.join(DIRNAME, r'/home/mk/Documents/DjangoTest2/templates'),
)

Also tried:
'/home/mk/Documents/DjangoTest2/templates',

and
os.path.join(BASE_DIR, 'templates'),

views.py:
def template_two(request):
view = "template_two"
t = get_template('myview.html')
html = t.render(Context({'name': view}))
return HttpResponse(html)

In this version it works:
def basic_one(request):
view = 'basic_one'
html = 'This is %s view' % view
return HttpResponse(html)

Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Inishev, 2016-05-22
@Millerish

At least it should

DIRNAME = os.path.dirname(os.path.abspath(__file__))

M
Millerish, 2016-05-22
@Millerish

It was necessary to put the templates folder in the project folder. Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question