L
L
Leonid2019-07-07 22:36:15
Django
Leonid, 2019-07-07 22:36:15

How to make multiple templates in one model in django?

Please tell me how to get several templates in the DetailView model depending on the field of the model.
For example, there is a News model with the Article field. How to output a template depending on the article?
And if the template with the given article is not found, get the standard one.
Model example:

class News(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    article = models.CharField(blank=False,
                               null=False,
                               default="",
                               max_length=50,
                               verbose_name="Артикул",
                               db_index=True,
                               unique=True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2019-07-07
@stilet69

def get_template_names(self):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question