Reputation: 61
I am new to Python, using currently versión 3.8. I uploaded a basic Project into the Google Cloud platform. Unfortunately and despite trying all answers here, using urlsafe and reconstructing strings as a way to identify my object, the Google cloud either does not compile the code or once executed gives me errors I cannot trace because all are "proven solutions"
I created an object inherited from NDB
from google.cloud import ndb
class Contact(ndb.Model):
name = ndb.StringProperty()
phone = ndb.StringProperty()
email = ndb.StringProperty()
In my deletion form, I refer to its "id" using this call
<form action="/delete" method="post">
<input type="hidden" name="uid" value="{{ contact.key.id() }}">
<button type="submit">Eliminar</button>
</form>
in my main program, the delete function (method) I use this:
@app.route(r'/delete', methods=['POST'])
def delete_contact():
client = ndb.Client()
with client.context():
contact = Contact.get_by_id(int(request.form.get('uid')))
contact.key.delete()
return render_template('contact.html')
This is the original code and it is supposed to work. I check the documentation and tried other alternatives that compile but give me execution errors such as the urlsafe. It compiles but does not work even when I get the key in my handler.
The line that does not compile is "contact.key.delete()". The contact is indeed retreived but somehow the method to delete it does not work.
Any ideas? I am new to Python, so I will prefer a solution rather than an explanation, thanks.
Carlos
Upvotes: 1
Views: 19
Reputation: 61
Even though nobody answered me, I finally got it fixed despite the errors. I had a serialization error, a defname error in that method (I had to separate def from the name of the method itself), an ahref error fixed by writing "a href", an indentation error and an invalid method error. Since I was uploading everything into the Google Cloud, it suddenly started working by itself!
Upvotes: 1