Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

render_to_response gives TemplateDoesNotExist

I am obtaining the path of template using

paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html')

and calling it in another application where paymenthtml gets copied to payment_template

return render_to_response(self.payment_template, self.context, RequestContext(self.request))

But I get error

TemplateDoesNotExist at /test-payment-url/

E:\testapp\template\payment.html

Why is the error coming?

Edit : I have made following change in settings.py and it is able to find the template, but i cannot hardcode the path in production, any clue?

TEMPLATE_DIRS = ("E:/testapp" )
like image 347
dhaval Avatar asked Dec 24 '09 06:12

dhaval


1 Answers

It seems like Django will only load templates if they're in a directory you define in TEMPLATE_DIRS, even if they exist elsewhere.

Try this in settings.py:

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
# Other settings...
TEMPLATE_DIRS = (
    os.path.join(PROJECT_ROOT, "templates"),
)

and then in the view:

return render_to_response("payment.html", self.context, RequestContext(self.request))
# or
return render_to_response("subdir/payment.html", self.context, RequestContext(self.request))

This would render either E:\path\to\project\templates\payment.html or E:\path\to\project\templates\subdir\payment.html. The point is that they're inside of the directory we specified in settings.py.

like image 172
John Debs Avatar answered Oct 04 '22 23:10

John Debs