Keine Ausgabe aus der Vorlage

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Keine Ausgabe aus der Vorlage

by Guest » 22 Feb 2025, 14:34

Ich übertrage die Informationen an meine Vorlage, aber wenn ich den lokalen Server lade, kann ich nichts sehen, wenn die erwartete Ausgabe eine Liste von Passwörtern ist, die in meiner Datenbank gespeichert werden. Ich habe eine Reihe von Druckanweisungen eingebracht, um den Code zu debuggen, aber es scheint, dass alles in Ordnung ist. Die Funktion, die den Code verarbeitet, lautet wie folgt: < /p>

Code: Select all

@app.route('/dashboard')
def dashboard():

if 'user' not in session:

print("User not found!!")
return redirect(url_for('login'))

user_id = session['user']['id']
print(f"\nDEBUG: Logged-in user ID -> {user_id}")  # Debugging

with sqlite3.connect('database.db') as conn:

cursor = conn.cursor()

cursor.execute('SELECT service, username, password FROM passwords WHERE user_id = ?', (user_id,))
rows = cursor.fetchall()

cursor.execute('SELECT COUNT(*) FROM passwords WHERE user_id = ?', (user_id,))
total_passwords = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*) FROM passwords WHERE user_id = ? AND strength = 'Strong'", (user_id,))
strong_count = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*) FROM passwords WHERE user_id = ? AND strength = 'weak'", (user_id,))
weak_count = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*) FROM bankcards WHERE user_id = ?", (user_id,))
total_cards = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*) FROM notes WHERE user_id = ?", (user_id,))
total_notes = cursor.fetchone()[0]

print("\nDEBUG: Retrieved passwords ->", rows)  #  Debugging

# Convert tuples into dictionaries for better template handling
passwords = [{'service': row[0], 'username': row[1], 'password': row[2]} for row in rows]

name = get_name(user_id)
# Check if passwords are passed to the template
response = render_template('dashboard.html',
user=session['user'],
passwords=passwords,
total_passwords=total_passwords,
strong_count=strong_count,
weak_count=weak_count,
total_cards=total_cards,
total_notes=total_notes,
name=name)
print("\nDEBUG: Rendering dashboard with passwords ->", passwords) # Debugging

return response
< /code>
Und dies ist der HTML -Code < /p>



{% if passwords %}

{% for entry in passwords %}




{{ entry.service[0]|upper }} 



{{ entry.service }} 
{{ entry.username }} 



[i]                                               value="{{ entry.password }}" readonly style="width: 150px; border: none; background: none;">



[/i]  




{% endfor %}
{% else %}
No saved passwords.
{% endif %}



Top