#35571: TypeError in assertTemplateUsed when using pathlib.Path as template_name
------------------------------------+--------------------------------------
     Reporter:  Erik Z.             |                    Owner:  nobody
         Type:  Bug                 |                   Status:  closed
    Component:  Testing framework   |                  Version:  5.0
     Severity:  Normal              |               Resolution:  invalid
     Keywords:  assertTemplateUsed  |             Triage Stage:  Unreviewed
    Has patch:  1                   |      Needs documentation:  0
  Needs tests:  0                   |  Patch needs improvement:  0
Easy pickings:  1                   |                    UI/UX:  0
------------------------------------+--------------------------------------
Changes (by Natalia Bidart):

 * resolution:   => invalid
 * status:  new => closed

Comment:

 Hello Erik, thank you for the sample Django project; it's been helpful.

 Now that I understand your issue, after reviewing the documentation
 thoroughly, I believe the problem stems from a potential misunderstanding
 of how the template name should be defined. You are using pathlib to
 define the template name, suggesting that the value could be a Path
 instance. However, the Django template system expects the template name to
 be a string identifier.

 If you refer to these sections in the documentation:

 * [https://docs.djangoproject.com/en/dev/topics/templates/#module-
 django.template.loader django.template.loader] "This function loads the
 template with the given name and returns a Template object."
 *
 
[https://docs.djangoproject.com/en/dev/topics/templates/#django.template.loader.render_to_string
 render_to_string] "template_name: The name of the template to load and
 render"

 The `template_name` should be a string, not a `Path` instance. It serves
 as an identifier for the template rather than a direct path in the
 filesystem. Each template loader then performs the necessary
 transformations or lookups using this identifier to find the requested
 template, utilizing whichever storage mechanism they are configured with
 (e.g., in-memory cache, filesystem, network-based storage, etc).

 I'll be closing this ticket accordingly, if you have further questions
 about this topic, please reach out to the Django community in the
 [https://forum.djangoproject.com/ Django Forum].
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35571#comment:6>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107019083572506-ff1c6e9a-aa8c-4c39-b8f8-c0f8c77263ca-000000%40eu-central-1.amazonses.com.

Reply via email to