#30197: Template variable resolution with class objects -------------------------------------+------------------------------------- Reporter: Alex Epshteyn | Owner: nobody Type: New feature | Status: closed Component: Template system | Version: master Severity: Normal | Resolution: duplicate Keywords: template, variable, | Triage Stage: resolve | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Alex Epshteyn): Replying to [comment:1 Tim Graham]: > Could you detail your use case a little more? What's `Foo.Bar` some nested class? Also, the discussion of `<type 'basestring'>` is outdated since basestring is removed in Python 3. If you can present a patch with a test, we can take a look, although I'm not sure it'll be backwards compatible. I guess a documentation change may be needed to describe the new behavior. "Foo.Bar" is just a label used in the example template -- it could be anything, really (I'll update the example to avoid this confusion). The actual class is not known until run-time (otherwise we wouldn't need to use our `type_name` filter in the first place :)). Let's just say that `foo` is some arbitrary object that has an attribute named "bar", whose value is a class. In my particular use case, the code is running on the Python 2.7 runtime of [https://cloud.google.com/appengine/docs/python/ Google App Engine] and `foo` is an instance of [https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.ext.db#google.appengine.ext.db.Property google.appengine.ext.db.Property], and `bar` is its "data_type" attribute (whose value is the Python class representing this datastore property's storage type). My template is listing all the properties defined for a particular datastore model class, including their storage type and other metadata. For many subclasses of `db.Property`, the `data_type` is `basestring`, but that's not really the point -- this template wouldn't work regardless of the data type and regardless of whether it's running on Python 2 or 3, because de-referencing this variable in a template returns a new instance of the data type rather than the data type itself. -- Ticket URL: <https://code.djangoproject.com/ticket/30197#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.d065cc318db16f8b4c8d610783d4db63%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.