开发者

Field-derived template names in Django class-based views

开发者 https://www.devze.com 2023-02-22 05:57 出处:网络
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 ow

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

精彩评论

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

关注公众号