Skip to content
The Chat Archive
claude-instant-1· Anthropic Arena Human Preference 55K

write a flask app for two routes search page and info page of search items. Also give me…

  1. User

    write a flask app for two routes search page and info page of search items. Also give me html,css and js code.

  2. Assistant

    Here is the code for a basic Flask app with two routes - a search page and an info page to display search results:

    from flask import Flask, render_template, request
    app = Flask(__name__)
    
    @app.route('/')
    def search():
       return render_template('search.html')
    
    @app.route('/info')
    def info():
       search_query = request.args.get('q')
       return render_template('info.html', query=search_query)
    
    if __name__ == '__main__':
       app.run(debug=True)
    

    search.html:

    <html>
    <head>
    <title>Search Page</title>
    </head>
    <body>
    
    <form action="/info">
    <input type="text" name="q">
    <input type="submit" value="Search">
    </form>
    
    </body>
    </html>
    

    info.html:

    <html>
    <head>
    <title>Search Results</title>
    </head>
    <body>
    
    <h1>Results for "{{ query }}"</h1>
    
    <p>Search results will be displayed here</p>
    
    </body>
    </html>
    

    style.css:

    body {
      font-family: Arial, sans-serif;
    }
    
    form {
      display: flex;
    }
    
    input[type=text] {
      padding: 5px;
    }
    
    input[type=submit] {
      padding: 5px 10px;
      margin-left: 10px;
      cursor: pointer;
    }
    

    This provides a basic search form on the homepage that passes the query string to the /info route, which displays the search term. You can expand on it to actually query an API/database and display results.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.