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" )
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With