# Flask Routes

> Started studying Flask with kendra-button project
>
> [Docs](https://pythonbasics.org/flask-tutorial-routes/)

<br>

## Route

* Receives URL patterns and executes registered Python methods when requests come in for URLs matching those patterns
  * Finding handler methods to process through URLs like this is called **URL Routing**!
  * To generate corresponding URLs in handlers, use the `url_for` method

<br>

### flask route example

* Flask routes are connected to Python functions
* Use the `@app.route()` decorator to connect URLs and functions

  ex)

  ```python
  @app.route('/hello')
  def hello_world():
     return "hello world!!!!"
  ```

<br>

### flask route params

* You can create routes with parameters
* You can pass `string` and `number` types as parameters

  ex)

  > string parameter

  ```python
  @app.route('/member/<name>')
  def get_member(name):
    return "Thank you for joining us " + str(name)
  ```

  > number parameter

  ```python
  @app.route('/sale/<transaction_id>')
  def get_sale(transaction_id=0):
    return "The transaction is "+str(transaction_id)
  ```

<br>

### flask route multiple arguments

* You can also create flask routes with multiple parameters

  ex)

  ```python
  @app.route('/create/<first_name>/<last_name>')
  def create(first_name=None, last_name=None):
    return 'Hello ' + first_name + ',' + last_name
  ```

\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chloe-codes1.gitbook.io/til/flask/flask_routes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
