עברתי על הסרטון כמה פעמים, כתבתי בעצמי בקוד תוך כדי ועדיין מקבל שגיאה:
עולה לי האתר:
כשאני מזין שם של פוקימון אני מקבל שגיאה בcmd
pokemon_name = request.args.get(‘pokemon’).lower()
AttributeError: ‘NoneType’ object has no attribute ‘lower’
הקוד של קובץ app.py נראה ככה:
from flask import Flask, render_template, request
import requests
app = Flask(__name__)
@app.route('/')
def hello_world():
pokemon_name = request.args.get('pokemon').lower()
if not pokemon_name:
return render_template('index.html')
print(pokemon_name)
resp = requests.get(f'https://pokeapi.co/api/v2/pokemon/{pokemon_name}')
resp_json = resp.json()
images = resp_json['sprites']
images = {k: v for k, v in images.items() if isinstance(v, str)}
return render_template(
'index.html',
name=pokemon_name,
sprites = images,
)
בגלל שאני לא ממש מבין איך לדבג את זה ומה הולך לאן בקוד נתקעתי, מההערה שבcmd נראה שמה שאני מקבל בrequest.args.get(‘pokemon’) זה none, ולא מחרוזת ולכן אני לא יכול להפעיל את הפונקציה lower(). אבל אין לי מושג איך לפתור זאת, ניסיתי לקרוא באינטרנט מה קורה שם עם הrequest וזה לא ברור לי איך המידע מגיע לrequest.