class ArticleDetailView(DetailView):
template_name = None
template_name_field = None
- Why
template_name_fielddefault value is None? template_name_fielddefault value will be'article_detail.html'
class ArticleDetailView(DetailView):
template_name = None
template_name_field = None
template_name_field default value is None?template_name_field default value will be 'article_detail.html'
- Why
template_name_fielddefault value isNone?
The template_name_field=… [Django-doc] specifies the name of an attribute of the object to look for when determining the template. In case it is None, Django will not look for such attribute. You however do not need to specify template_name_field=None: this is already the case due to inheritance, so the template_name_field = None line is not neccesary.
template_name_fielddefault value will be'article_detail.html'
No, you can use the template_name=… [Django-doc] to specify the name of the template. The template_name_field specifies the name of an attribute of the object that specifies the name of the template. In other words, you could have a model:
class Article(models.Model):
template_to_render = models.CharField(max_length=128)
where you thus have for example a field that contains the name of the template to render, then you can set template_name_field='template_to_render'. Django will thus then for that object look for that attribute, and in case such attribute exists use that as the name of the template to render.
In case both template_name and template_name_field are None, Django will make a final fallback and look for the name of the model (here likely Article), and will try to render a template named app_name/modelnamesuffix.html with app_name the name of the app where you defined the model, modelname the name of the model in lowercase (so here article), and suffix the value for the template_name_suffix=… attribute [Django-doc], which is by default '_detail', so it will look for a template named app_name/article_detail.html with app_name the name of the app where you defined the Article model.