Я использую код, который использовал ранее, но выдает ошибку, 'TemplateDoesNotExist в / inventory / render_results /' , и я не могу найти опечатку или логи c miss. Шаблон существует, и когда я проверяю код, запрос выполняется правильно. Я в недоумении.
search_device_list. html
{% extends "inventory/base.html" %}
{% block content %}
<h2 align="left">Search Page</h2>
<form action="{% url 'render_results' %}" method="POST" >
{% csrf_token %}
<body>
<table>
<tr>
<td><b>Locations: </b></td>
<td>
<select name="location_name">
{% for locations in locations %}
<option value="{{locations.location_name}}">{{locations.location_name}}</option>{% endfor%}
</select>
</td>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
{% endblock content %}
render_results. html
<html>
<h2 align="left">Render Device List based on Location Choice</h2>
<b> Locations: </b><br>{{locations }} <br><br><br>
<b> Devices: </b><br>
{% for device in devices %}{{device.device_name}} <br>{% endfor %} </td>
<br>
<button type="submit" id="save">Save</button>
</html>
views.py
def render_results (request):
location_name = request.POST.get('location_name')
my_devices = Devices.objects.filter(locations = Locations.objects.get(location_name = location_name))
context = {"devices": my_devices,
"locations": location_name}
return render(request, 'inventory/render_results.html', context)
def search_device_list(request):
locations = Locations.objects.all()
print(locations)
context = {"locations": locations}
for locations in context['locations']:
print(locations)
location_name=request.POST.get('location_name')
if request.method == 'GET':
form = LocationsForm()
print(locations)
return render(request, 'inventory/search_device_list.html', context)
и, наконец, URL-адреса. py
...
url(r'^search_device_list/$', views.search_device_list, name='search_device_list'),
url(r'^render_results/$', views.render_results, name='render_results'),