so i have this page where after you login there is a dashboard where it show a bunch of site, and when i click the add button it show a pop up where you write a site and than when you click add it add a div on the dashboard and save the "link" on a database SQL.
but when i try to delete a site(div) with an id it doesn't work, im using a method post.
what i want is when i click the button the div will be removed from the database and that means from the dashboard.
python code
@app.route("/", methods=["GET", "POST"])
@login_required
def delete():
user_id = session.get("user_id")
name = db.execute(
"SELECT first_name FROM users WHERE user_id = (?)", user_id)
id = db.execute(
"SELECT site_id, site_name, username, password FROM sites WHERE user = (?)",
user_id)
last = db.execute(
"SELECT last_name FROM users WHERE user_id = (?)", user_id)
if request.method == "POST":
site_username = request.form.get("site_username")
site_password = request.form.get("site_password")
rows = db.execute("SELECT password FROM sites WHERE password = ?",
request.form.get("site_password"))
for word in rows:
return word
if not site_password == word:
return redirect("/")
db.execute(
"DELETE sites_id FROM sites WHERE (username, password, user) VALUES( ?, ?, ?)", site_username, site_password, user_id)
return redirect("/")
return render_template("index.html", name=name, last=last, id=id)
HTML
<ul role="list"
class="grid grid-cols-1 gap-6 sm:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 justify-items-center">
{% for n_site in id %}
<li class=" max-w-md col-span-1 bg-white rounded-lg shadow divide-y divide-gray-200 my-7 w-full">
<div class="p-7">
<h1 class="text-2xl font-semibold text-center ">{{n_site["site_name"]}}</h1>
<div class="hidden">{{n_site["site_id"]}}</div>
<div class="mt-6">
<div>
<label for="username" class="block text-sm font-medium text-gray-700">Username</label>
<div type="text" name="site_username" id="site_username"
class="appearance-none break-words block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
{{n_site["username"]}}
</div>
<div class="mt-4">
<div class="flex items-center justify-between">
<label for="password" class="block text-sm font-medium text-gray-700">Password</label>
</div>
<div name="site_password" id="site_password"
class="appearance-none relative break-words block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
{{n_site["password"]}}
</div>
</div>
</div>
<form class="pt-6 flex justify-end" method="post" action="{{ url_for('delete') }}">
<button
class="text-white object-right-bottom bg-red-600 hover:bg-red-700 focus:ring-4 focus:outline-none focus:ring-red-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center"
type="submit" value={{site_id}} name=site_to_delete>
Delete
</button>
</form>
</div>
</div>
</li>
{% endfor %}