Se un modello manca nel profondo del rendering di un modello django, ottengo un'eccezione come di seguito.Messaggio di errori migliori se manca il modello
Dopo aver cercato molto tempo ho trovato la parte falsa:
{% include form.template_name %}
form.template_name era vuota nel mio contesto.
Come posso trovare il nome del modello pertinente senza cercare ore?
Mi manca un traceback come per il normale codice Python. I traceback "normali" di python mostrano il file e la riga che contengono il bug.
/home/foo_fm_d/bin/python /usr/local/pycharm-community-4.5/helpers/pycharm/utrunner.py /home/foo_fm_d/src/foo-time/foo_time/tests/unit/views/user/test_preview_of_next_days.py::EditTestCase::test_preview_of_next_days true
Testing started at 09:26 ...
Error
Traceback (most recent call last):
File "/home/foo_fm_d/src/foo-time/foo_time/tests/unit/views/user/test_preview_of_next_days.py", line 11, in test_preview_of_next_days
self.admin_client.get(url)
File "/home/foo_fm_d/src/djangotools/djangotools/utils/testutils.py", line 275, in get
response = super(Client, self).get(path, data, **extra)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/test/client.py", line 473, in get
response = super(Client, self).get(path, data=data, **extra)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/test/client.py", line 280, in get
return self.request(**r)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/test/client.py", line 444, in request
six.reraise(*exc_info)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 137, in get_response
response = response.render()
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/response.py", line 105, in render
self.content = self.rendered_content
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/response.py", line 82, in rendered_content
content = template.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 140, in render
return self._render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 840, in render
bit = self.render_node(node, context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/debug.py", line 78, in render_node
return node.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render
return compiled_parent._render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 840, in render
bit = self.render_node(node, context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/debug.py", line 78, in render_node
return node.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render
return compiled_parent._render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 840, in render
bit = self.render_node(node, context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/debug.py", line 78, in render_node
return node.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 840, in render
bit = self.render_node(node, context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/debug.py", line 78, in render_node
return node.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/debug.py", line 88, in render
output = self.filter_expression.resolve(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 585, in resolve
obj = self.var.resolve(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 735, in resolve
value = self._resolve_lookup(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 789, in _resolve_lookup
current = current()
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 72, in super
return mark_safe(self.render(self.context))
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 840, in render
bit = self.render_node(node, context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/debug.py", line 78, in render_node
return node.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 840, in render
bit = self.render_node(node, context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/debug.py", line 78, in render_node
return node.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/base.py", line 840, in render
bit = self.render_node(node, context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/debug.py", line 78, in render_node
return node.render(context)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 166, in render
template = get_template(template_name)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader.py", line 138, in get_template
template, origin = find_template(template_name)
File "/home/foo_fm_d/local/lib/python2.7/site-packages/django/template/loader.py", line 131, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist
Process finished with exit code 0
Aggiornamento
personali: Fino ad ora evito di modelli Django dato che a volte eccezioni vengono silenziosamente ignorati e traceback come questo rendono il processo di debug voglia di indossare scarpe pesanti in calcestruzzo.
Cerco di liberarmi dei miei pregiudizi. O almeno trovare un modo per ottenere migliori messaggi di errore dai modelli.
Aggiornamento II
vedo la traceback tramite un unittest all'interno PyCharm. Non leggo il risultato della vista. Il client "webbrowser" chiama la vista. Ho impostato TEMPLATE_DEBUG = True, ma il risultato è lo stesso.
Hai provato questo: https://docs.djangoproject.com/en/1.8/ref/settings/#template-debug? – Wtower
@Wtower Vedo il traceback tramite un pyCharm interno. Non leggo il risultato della vista. Il client "webbrowser" chiama la vista. Ho impostato TEMPLATE_DEBUG = True, ma il risultato è lo stesso. – guettli
Sfortunatamente 'TEMPLATE_DEBUG = True' si basa su' DEBUG = True' e quella variabile viene automaticamente impostata su 'False' quando vengono eseguiti i test. Potresti eseguire un server reale ('./manage.py runserver') e provare a riprodurlo nel browser con' TEMPLATE_DEBUG = DEBUG = True' nelle tue impostazioni? – Weier