I'm making a simple web app that sends, deletes and edits data to a MariaDB database and I'm using Flask as a framework. Currently, the app.py script is fully working except for the editing API, responding a 405 Status. I've already checked my website config and especially the URLs. I checked also the DB config if it allows to change data from the web app and nothing. This is my repo: https://www.github.com/Its-Yayo/f-test
I'm deducing the problem is right here:
@app.route("/edit_contact/<id>", methods=['POST']) # Here
def get_contact(id: int) -> str:
# FIXME: 405 Method Not Allowed
conn = connection()
cur = conn.cursor()
cur.execute('SELECT * FROM contacts WHERE idcontact = %d', (id)) # Or here
data = cur.fetchall()
print(data[0]) # Debug Message
return render_template('edit.html', contact=data[0]) # It doesn't ever render the file
I'm expecting a 302 Status that responses the edit.html file but seems the URL is wrong. However, the method that deletes data has the same config as in the index.html and it works perfectly. I set up the URLs here
{% for contact in contacts %}
<tr>
<td>{{ contact.1}}</td>
<td>{{ contact.2}}</td>
<td>{{ contact.3}}</td>
<td>
<a href='/edit_contact/{{ contact.0 }}'>Edit</a>
<a href='/delete_contact/{{ contact.0 }}'>Delete</a>
</td>
</tr>
{% endfor %}
However I'm still troubleshooting to check and fix this error. Any help or PR will be welcomed.