Forums

Django appears to generate its own template when rendering in python anywhere, resulting in errors

See error below :

TemplateNameDoes not Exist (commspace\index.html, starnec/blogpost_list.html).

I have specified my template onl as (commspace\index.html) in my generic.ListView. All the other views that are not generic.listviews are working correctly. Also blogpost is the model s name.

Are you sure that you're running the same version of Django on PythonAnywhere as the code was written for? Are you sure that the paths that you have configured for your template directories actually exist on PythonAnywhere?

What I find curious is the paths in the error: TemplateNameDoes not Exist (commspace\index.html, starnec/blogpost_list.html). Given path in my view

1.Are you sure that you're running the same version of Django on PythonAnywhere as the code was written for: Yes. Other templates for views in the same app are running ok. 2. ..paths that you have configured for your template directories actually exist on PythonAnywhere Have checked. Will paste in here 2 views in the same app. class PostList(generic.ListView):

 queryset = BlogPost.objects.filter(bp_status='P').order_by('-ad_date_c')
 template_name = 'starnec\commspace\index.html'

 context_object_name = 'post_list'
 paginate_by = 20
 class PostListAdmin(generic.ListView):

 queryset = BlogPost.objects.exclude(bp_status='P').order_by('-ad_date_c')
 template_name = 'starnec\commspace\index.html'

 context_object_name = 'post_list'
 paginate_by = 20

Two views above are the problem ones. Generic list view ones. One below is Ok.

 class AffilBodyIndexView(ListView): template_name = 'starnec/membspace/affilbody/index.html'      context_object_name = 'affilbody_list'

 def get_queryset(self):
     return AffilBody.objects.all()

That's probably because you are including/inheriting from the other template in the first template and that would mean (I think) that either the second template does not exist or that the path to the template folder for that template is incorrect in some way.

The second template does not exists and think that is the cause of the problem. Need to know how to get rid of it.

Remove the reference to it in the first template.

Have searched all templates. No reference to blogpost_list.html

It would views appear class based generic by default look for and generate own templates derived from the model(Explains the blogpost_list.html . Whereas this can be over written by specifying the template_name variable (Which is working in my local development environment), appears not to work now in python anywhere. That appears to be my problem now. How to make template_name override the default behaviour. Otherwise, I may have to change to function based view. See below:

Note: This awkward path for the template location isn't a misprint — the generic views look for templates in /application_name/the_model_name_list.html (catalog/book_list.html in this case) inside the application's /application_name/templates/ directory (/catalog/templates/).

Then it may be in a view or other code. Make sure that you are looking at the templates that are actually being used by your web app.

You can try running:

grep -R "blogpost_list.html" *

in the root of your Django directory to find the reference.

Thank you friends because you are going to forgive me. Indeed it was generating an additional generic template. Reason being it could not find one specified in the view. Reason It could not find one specified in view was cause I had back slashes for the blog views instead of forward slashes. Changed that and it worked. Wondering why it worked with back slashes in the local dev environment.

Thank you again for your willingness to help and so sorry.

Great! Glad we could help.