gpt-4.1-2025-04-14· OpenAI LMArena Human Preference 140K
Create a recipe management website
- User
Create a recipe management website
- Assistant
Absolutely! Below is a simple recipe management website built with Python (Flask) for the backend and HTML/CSS/Bootstrap for the frontend. This app allows users to:
- View all recipes
- Add a new recipe
- View recipe details
You can expand it with editing, deleting, user authentication, etc.
1. Project Structure
recipe_app/ │ ├── app.py ├── templates/ │ ├── base.html │ ├── index.html │ ├── add_recipe.html │ └── recipe_detail.html └── static/ └── style.css
2.
app.py(Flask Backend)from flask import Flask, render_template, request, redirect, url_for app = Flask(__name__) # In-memory "database" recipes = [ { 'id': 1, 'title': 'Spaghetti Carbonara', 'ingredients': 'Spaghetti, Eggs, Pancetta, Parmesan, Black Pepper', 'instructions': '1. Cook spaghetti. 2. Fry pancetta. 3. Mix eggs and cheese. 4. Combine all.' } ] def get_next_id(): return max([r['id'] for r in recipes], default=0) + 1 @app.route('/') def index(): return render_template('index.html', recipes=recipes) @app.route('/recipe/<int:recipe_id>') def recipe_detail(recipe_id): recipe = next((r for r in recipes if r['id'] == recipe_id), None) if not recipe: return "Recipe not found", 404 return render_template('recipe_detail.html', recipe=recipe) @app.route('/add', methods=['GET', 'POST']) def add_recipe(): if request.method == 'POST': title = request.form['title'] ingredients = request.form['ingredients'] instructions = request.form['instructions'] new_recipe = { 'id': get_next_id(), 'title': title, 'ingredients': ingredients, 'instructions': instructions } recipes.append(new_recipe) return redirect(url_for('index')) return render_template('add_recipe.html') if __name__ == '__main__': app.run(debug=True)
3.
templates/base.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Recipe Manager</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> </head> <body> <nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4"> <div class="container"> <a class="navbar-brand" href="{{ url_for('index') }}">Recipe Manager</a> <a class="btn btn-success" href="{{ url_for('add_recipe') }}">Add Recipe</a> </div> </nav> <div class="container"> {% block content %}{% endblock %} </div> </body> </html>
4.
templates/index.html{% extends 'base.html' %} {% block content %} <h2>All Recipes</h2> <div class="row"> {% for recipe in recipes %} <div class="col-md-4"> <div class="card mb-4"> <div class="card-body"> <h5 class="card-title">{{ recipe.title }}</h5> <a href="{{ url_for('recipe_detail', recipe_id=recipe.id) }}" class="btn btn-primary">View</a> </div> </div> </div> {% endfor %} </div> {% endblock %}
5.
templates/add_recipe.html{% extends 'base.html' %} {% block content %} <h2>Add New Recipe</h2> <form method="post"> <div class="mb-3"> <label for="title" class="form-label">Recipe Title</label> <input type="text" class="form-control" id="title" name="title" required> </div> <div class="mb-3"> <label for="ingredients" class="form-label">Ingredients</label> <textarea class="form-control" id="ingredients" name="ingredients" rows="3" required></textarea> </div> <div class="mb-3"> <label for="instructions" class="form-label">Instructions</label> <textarea class="form-control" id="instructions" name="instructions" rows="4" required></textarea> </div> <button type="submit" class="btn btn-success">Add Recipe</button> </form> {% endblock %}
6.
templates/recipe_detail.html{% extends 'base.html' %} {% block content %} <h2>{{ recipe.title }}</h2> <h5>Ingredients:</h5> <p>{{ recipe.ingredients }}</p> <h5>Instructions:</h5> <p>{{ recipe.instructions }}</p> <a href="{{ url_for('index') }}" class="btn btn-secondary">Back to Recipes</a> {% endblock %}
7.
static/style.css(Optional)body { background-color: #f8f9fa; } .card-title { font-size: 1.25rem; }
8. How to Run
- Save the files as shown above.
- Install Flask:
pip install flask - Run the app:
python app.py - Visit http://127.0.0.1:5000/ in your browser.
You now have a basic recipe management website!
You can expand it with features like editing, deleting, user accounts, image uploads, and a database (e.g., SQLite) for persistence. Let me know if you want to add any of these features!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.