django-silk
django-silk copied to clipboard
Cleardb view context error
Here's some code in clear_db.html
:
{% block data %}
<div class="wrapper">
<div class="inner">
<h2>Silk Clear DB</h2>
<form class="cleardb-form" action="." method="post">
{% csrf_token %}
<div class="cleardb-form-wrapper">
<label>
<input type="checkbox" name="clear_requests" disabled="disabled"/>
Requests
</label>
<label>
<input type="checkbox" name="clear_profiling" disabled="disabled"/>
Profiling
</label>
<label>
<input type="checkbox" name="clear_all"/>
All
</label>
</div>
<button class="btn">Clear</button>
</form>
<div class="msg">{{ msg }}</div>
</div>
</div>
{% endblock %}
Here's the code of view:
class ClearDBView(View):
@method_decorator(login_possibly_required)
@method_decorator(permissions_possibly_required)
def get(self, request, *_, **kwargs):
return render(request, 'silk/clear_db.html')
@method_decorator(login_possibly_required)
@method_decorator(permissions_possibly_required)
def post(self, request, *_, **kwargs):
context = {}
if 'clear_all' in request.POST:
delete_model(Profile)
delete_model(SQLQuery)
delete_model(Response)
delete_model(Request)
tables = ['Response', 'SQLQuery', 'Profile', 'Request']
context['msg'] = 'Cleared data for following silk tables: {0}'.format(', '.join(tables))
return render(request, 'silk/clear_db.html', context=context)
The important lines are:
<div class="msg">{{ msg }}</div>
def get(self, request, *_, **kwargs):
return render(request, 'silk/clear_db.html')
def post(self, request, *_, **kwargs):
context['msg'] = 'Cleared data for following silk tables: {0}'.format(', '.join(tables))
We can see, only post have msg
variable but both get and post need it.
I wanted to send a PR, but the project is unable to run on my windows device, so just record it here, hope to fix it.
Can you paste the full traceback of your error? It should not be an error if the variable is inexistent