Reputation: 7399
I have an app that runs some long running tasks and I am showing the log of runs (a table) that a user has made on a particular page. There is a result location in the table on the page, where I would like for it to be a hyperlink and when clicked, gets redirected to a page where the user can see the result.
I am getting a :
NoReverseMatch: Reverse for 'past_run_results' with arguments '(u'1649103c-67d0-47f9-a085-401c02acff6a',)' not found. 1 pattern(s) tried: ['discovery-engine/past-runs/(P<task_id>[-\\w]+)$']
and I can't figure out what is wrong
/urls.py
[
url(r'^past-runs/$', views.past_run_log, name="previous_runs"),
url(r'^past-runs/(P<task_id>[-\w]+)$', views.past_run_results, name="past_run_results"),
]
/views.py
def past_run_log(request):
past_fifty_runs = JobLog.objects.all().filter(user=request.user)[:50]
context_dict = {"past_runs": past_fifty_runs}
return render(request, 'website/previous_runs.html', context=context_dict)
def past_run_results(request, task_id):
get_result = JobLog.objects.get(task_id=task_id)
read_location = os.path.join(os.getcwd(), "results", get_result.result_location)
with open(read_location) as f:
result_data = json.load(f)
if result_data:
return render(request, 'website/previous_runs_results.html', context={"result": result_data})
else:
return render(request, 'website/previous_runs_results.html', context={"result": "No result found."})
/previous_runs.html
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<h1>History</h1>
<table data-toggle="table" data-search="true" data-pagination="true" class="table-responsive">
<thead>
<tr>
<th>Task Name</th>
<th>Username</th>
<th>Algortihm Name</th>
<th>Start Time</th>
<th>Duration (secs)</th>
<th>Status</th>
<th>Result</th>
</tr>
</thead>
<tbody>
{% for run in past_runs %}
<tr>
<td>{{run.task_name}}</td>
<td>{{run.user}}</td>
<td>{{run.algorithm}}</td>
<td>{{run.time_started}}</td>
<td>{{run.time_taken | floatformat:2}}</td>
<td>{{run.status}}</td>
<td><a href="{% url 'past_run_results' run.task_id %}">{{run.result_location}}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
The task_id is a unique key such as 1649103c-67d0-47f9-a085-401c02acff6a
.
Django version is 1.11
and python version 2.7
Upvotes: 0
Views: 95