I'm having trouble figuring out how to load a template from a model's field name in Django's new class-based views. Basically I'm looking for the functionality of Django contrib flatpages in my own model like so:
class MyModel(models.Model):
template_name = CharField(_('Template name'), max_length=255)
Time was I'd just lookup the object and then RenderResponse using the template_name field's valu开发者_JS百科e. I suppose I could do that with class-based views, but is there are more appropriate way?
Not entirely sure where you're having problems, but it sounds like the SingleTemplateResponseMixin would help - it has a template_name_field
attribute which is set to the name of the field containing the name of the template.
精彩评论