First time here? Check out the FAQ!
0

Template not found
 

Hi I have added a app to askbot the way I have done is I have created my app inside askbot folder: So the structure looks like follows:

askbot
|__Templates
|__Views
|__ Utils
|__ upfiles
|__ ... 
|__ experiments
      |__ __init__.py
      |__...
      |__templates
           |__experiments
                |__ *.html
                |__Include
                     |_experiment_enrollment.html

but the problem is I am getting template not found: The error is bit confusing to understand:

My exact error is as follows:

TemplateNotFound at /questions/
askbot/experiments/templates/experiments/include/experiment_enrollment.html
Request Method: GET
Request URL:    http://localhost:8001/questions/
Django Version: 1.4.10
Exception Type: TemplateNotFound
Exception Value:    
askbot/experiments/templates/experiments/include/experiment_enrollment.html
Exception Location: /Users/mac/code/vEnv/myanswers/askbot/templates/base.html in top-level template code, line 3
Python Executable:  /Users/mac/code/vEnv/myanswers/bin/python
Python Version: 2.7.5
Python Path:

What might i be doing wrong here..?

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
SocialQA's avatar
265
SocialQA
asked 11 years ago

Comments

How are you rendering the template in the views?

Evgeny's avatar Evgeny (11 years ago)

for an example `def experiment_details(request, experiment_name, template_name="experiments/experiment_details.html"):`

SocialQA's avatar SocialQA (11 years ago)

Try the `TEMPLATE_DIRS` setting to add the directory.

Evgeny's avatar Evgeny (11 years ago)

by default its commented so should I uncomment and add the dir of the new project to that..?

SocialQA's avatar SocialQA (11 years ago)

Look into the Django documentation for that info.

Evgeny's avatar Evgeny (11 years ago)
see more comments

1 Answer

1

Try adding your template directory to setting TEMPLATE_DIRS.

Also, if you put your templates inside the askbot/templates it should work if you do something like this:

from django.shortcuts import render
return render(request, 'experiments/template.html', template_data)

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 11 years ago
link

Comments

In the current setting TEMPLATE_DIR is commented and there is a note saying read: http://askbot.org/en/question/2669/jinja-includes-and-extends-path-issue/ based on that looks like if I turn on TEMPLATE_DIR entire askbot TEMPLATES will change because it will try to read the tempaltes from that location..? But all I want is templates related to the new app to read from that location.

SocialQA's avatar SocialQA (11 years ago)

I want to add following to base.html so this script would be available in all the templates: Is it ok to add such things to base.html. <script language="javascript" src="{% get_static_prefix %}javascripts/experiments.js" type="text/javascript"> {% include "experiments/include/experiment_enrollment.html" %}

SocialQA's avatar SocialQA (11 years ago)
1

Sure, why not.

Evgeny's avatar Evgeny (11 years ago)

can you confirm on one thing: If I put the template path of the application that I have added inside askbot folder to TEMPLATE_DIR, entire askbot will use that location instead of askbot/templates?

SocialQA's avatar SocialQA (11 years ago)

if the experiments is inside askbot should I be adding {% include "askbot/experiments/include/experiment_enrollment.html" %} or experiments/include/experiment_enrollment.html

SocialQA's avatar SocialQA (11 years ago)
see more comments