'Why do I keep on getting a flask NoAppException error
Keep on getting flask.cli.NoAppException error. Not sure how to fix this. I have been working on this for two days. I think it could be something to do with the dictionaries or my for loop isn't set up right. If anyone could help with this project it would be very much appreciated.
from flask import Flask
from helper.py import pets
app = Flask(__name__)
@app.route('/')
def index():
return '''
<h1>Adopt a Pet!</h1>
<p>Browse through the links below to find your furry friend:</p>
<ul>
<li><a href='animals/dogs'>Dogs</a></li>
<li><a href='animals/cats'>Cats</a></li>
<li><a href='animals/rabbits'>Rabbits</a></li>
</ul>
'''
@app.route('/animals/<pet_type>')
def animals(pet_type):
html = f"<h1>List of {pet_type}</h1>"
html += "<ul>"
for item in pets[pet_type]:
htlm += "<li>" + f'<a href="/animals/{pet_type}">' + item["name"] + "</a></li>"
html += "</ul>"
return html
@app.route("/animals/<pet_type>/<int:pet_id>")
def pet(pet_type, pet_id):
pet = pets[pet_type][pet_id]
pet = {
'name': pet_type['name'],
'age': pet_type['age'],
'breed': pet_type['breed'],
'description': pet_type['description'],
'url': pet_type['url']
}
Solution 1:[1]
This is the problem solved
from flask import Flask
from helper import pets
app = Flask(__name__)
@app.route('/')
def index():
return '''
<h1>Adopt a Pet!</h1>
<p> Browse through the links bewlow to find your new furry friend </p>
<ul>
<li><a href="/animals/dogs">Dogs</a></li>
<li><a href="/animals/cats">Cats</a></li>
<li><a href="/animals/rabbits">Rabbits</a></li>
</ul>
'''
@app.route('/animals/<pet_type>')
def animals(pet_type):
html = f"<h1>List of {pet_type}</h1>"
html += '<ul>'
for idx, item in enumerate(pets[pet_type]):
html += f'<li><a href="/animals/{pet_type}/{idx}">' + item["name"] +'</a></li>'
html += '</ul>'
return html
@app.route('/animals/<pet_type>/<int:pet_id>')
def pet(pet_type, pet_id):
pet = pets[pet_type][pet_id]
return f'''
<h1> {pet["name"]} </h1>
<img src="{pet["url"]}"/>
<p>{pet["description"]}</p>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shawn Mason |
