I am having trouble deleting entities from keys in the GAE using python/ndb. I am able to retrieve the entity (problem) key from the page, but cannot figure out how to get it to delete. The GAE support page says it's as simple as retrieving the key and then deleting it, as seen below.
problem = problem_key.get()
problem.key.delete()
But this is not working. I'm pretty sure the key is being obtained correctly. The HTML looks like
{%for problem in problems %}
<tr>
<td>{{ problem.tags }}</td>
<td><script type="math/tex">{{ problem.content }}</script></td>
<td>{{ problem.answer }}</td>
<td>{{ problem.quiz }}</td>
<td>{{ problem.id }}</td>
<td>{{ problem.date }}</td>
<form action="/deleteProblem" method="POST">
<td><button type="submit" name="problem_key" value="{{ problem.key }}">Delete Problem</button></td>
</form>
</tr>
{% endfor %}
And my python code looks like:
class deleteHandler(BaseHandler):
def post(self):
prob_key = self.request.get('problem_key')
problem = prob_key.get()
problem.key.delete()
self.redirect("/")
I'm getting:
problem = prob_key.get()
AttributeError: 'unicode' object has no attribute 'get'
My best guess is that prob_key is getting assigned the actual unicode and so of course there is no get()
method for it but I don't understand how to fix the problem based on Google's explanation of how it should function.