A Flask web application that fetches and displays dog images by breed using the Dog CEO API. Users can browse through different dog breeds and view random images of their selected breed.
This Flask application integrates with the Dog CEO API to fetch and display dog images based on breed selection. The project demonstrates API integration, dynamic routing, form handling, and template rendering with Jinja2.
- API Integration: Fetches data from Dog CEO API
- Breed Selection: Form-based breed selection interface
- Dynamic Routing: Flask routes handle breed-specific requests
- Random Dog Images: Displays random images for selected breeds
- Jinja2 Templating: Dynamic content rendering
- Responsive Design: Mobile-friendly interface
- Backend: Python, Flask
- API: Dog CEO API (https://dog.ceo/dog-api/)
- Templating: Jinja2
- Frontend: HTML5, CSS3
- HTTP Requests: Flask's built-in request handling
This project demonstrates:
- Making HTTP requests to external APIs
- Processing JSON responses from APIs
- Working with Flask forms and user input
- Dynamic routing with URL parameters
- Passing data from Flask routes to templates
- Error handling for API requests
- Template rendering with dynamic data
Check if Python is installed:
On Mac:
python3 --versionOn Windows:
python --versionEnsure you have Python 3.8 or higher installed (3.11 recommended). If you need to install Python on Windows, see this guide.
git clone https://github.com/CatYoung018/dog-image-gallery.git
cd dog-image-galleryOn Mac:
python3 -m venv venvOn Windows:
python -m venv venvOn Mac:
source venv/bin/activateOn Windows:
source venv/Scripts/activateOnce activated, you'll see (venv) at the beginning of your terminal prompt.
pip install flask flask-sqlalchemyWithout debugger:
flask runWith debugger (recommended for development):
flask run --debugThe app will run at: http://127.0.0.1:5000/
- Open your browser and navigate to
http://127.0.0.1:5000/ - Select a dog breed from the dropdown menu
- Submit the form to view random images of that breed
- Refresh to see different random images
- Press
Ctrl + Cto stop the server - Run
deactivateto close the virtual environment
Note: When not using the debugger, you'll need to stop and restart the server after making code changes. Remember to hard refresh your browser (Ctrl + F5 or Cmd + Shift + R).
dog-image-gallery/
โโโ static/ # Static assets
โ โโโ css/ # Stylesheets
โ โ โโโ style.css # Main stylesheet
โ โโโ images/ # Local images (if any)
โโโ templates/ # HTML templates (Jinja2)
โ โโโ index.html # Homepage with breed selection
โ โโโ breed.html # Breed-specific image display
โโโ app.py # Main Flask application
โโโ .gitignore # Git ignore file
โโโ README.md # Project documentation
โโโ venv/ # Virtual environment (after setup)
- User visits the homepage
- Form displays available dog breeds
- User selects a breed and submits
# Flask makes request to Dog CEO API
response = requests.get(f'https://dog.ceo/api/breed/{breed}/images/random')
data = response.json()- Flask processes the JSON response
- Extracts image URL from API data
- Passes URL to template via Jinja2
- Template displays the dog image
@app.route('/breed/<breed_name>')
def show_breed(breed_name):
# Fetch and display images for specific breedView a specific breed:
http://127.0.0.1:5000/breed/husky
http://127.0.0.1:5000/breed/beagle
http://127.0.0.1:5000/breed/corgi
Homepage:
http://127.0.0.1:5000/
This project uses the Dog CEO API:
- List all breeds:
https://dog.ceo/api/breeds/list/all - Random image by breed:
https://dog.ceo/api/breed/{breed}/images/random - Multiple images:
https://dog.ceo/api/breed/{breed}/images/random/{count}
- Add search functionality for breeds
- Display multiple images per breed
- Add breed information and descriptions
- Implement favorites/save feature
- Add pagination for large breed lists
- Include sub-breeds (e.g., retriever/golden)
- Add image download functionality
- Implement caching for faster loading
This project was created as part of a Skillcrush coding bootcamp, focusing on API integration with Flask and form handling.
API Credit: Dog images provided by Dog CEO API
This project is open source and available for educational purposes.
Cat Young
Email: cat@catyoungconsulting.com
Portfolio: catyoung018.github.io/Cat-Young-Dev
GitHub: @CatYoung018
โญ If you found this project helpful, please consider giving it a star!