开发者

Field-derived template names in Django class-based views

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜