I am trying to get the dynamic class name in django class based view .
Here is my class .
class ProductDetailView(TemplateView):
template_name = "%_%_details.html"
def get_template_names(self,tmp_name,tmp_name2):
return [self.template_name % tmp_name,tmp_name2]
def get_context_data(self, **kwargs):
context = super(ProductDetailView, self).get_context_data(**kwargs)
platform = self.request.GET.get('platform')
if platform == "AMAZON":
asin = self.request.GET.get('asin')
if asin:
#products = amazon.search(Keywords=q, SearchIndex='All')
products= amazon.lookup(ItemId=asin)
template_name = self.get_template_names('amazon','product')
context['products'] = products
I want to accees the template amazon_product_details.html .
I am getting the error unsupported format character '_' (0x5f) at index 1
while accessing the above view .
I tried urlib quoting also but that also doesn't work .
Please do let me know what might I am doing wrong here .
Looks like you're trying to use standard C-style string interpolation, but you're missing the actual formatting characters.
template_name = "%s_%s_details.html"
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