Compare commits

...

8 Commits

Author SHA1 Message Date
Badhreesh ca07265990
Merge 6e064b3ff2 into f04c5e6964 2025-06-09 01:09:43 -07:00
Badhreesh 6e064b3ff2
Fix typo 2025-05-22 12:56:14 +02:00
Badhreesh d4390442b7
Remove extra line 2025-05-22 12:52:54 +02:00
Badhreesh ac00a998a3 Remove extra wording 2025-05-22 12:52:11 +02:00
Badhreesh 5e3031e189 Move routing section back to original position 2025-05-22 12:51:00 +02:00
Badhreesh c8d80f690b Add reference to the request object section 2025-05-22 12:30:10 +02:00
Badhreesh d47ede1540 Demonstrate escaping without using path type 2025-05-22 12:22:49 +02:00
Badhreesh 0f2004c9e6 Initial commit 2025-05-21 20:35:11 +02:00
1 changed files with 11 additions and 6 deletions

View File

@ -139,19 +139,22 @@ how you're using untrusted data.
.. code-block:: python
from flask import request
from markupsafe import escape
@app.route("/<name>")
def hello(name):
@app.route("/hello")
def hello():
name = request.args.get("name", "")
return f"Hello, {escape(name)}!"
If a user managed to submit the name ``<script>alert("bad")</script>``,
User input can be submitted to the view function via the URL as query parameters,
like ``/hello?name=Bob``. Refer :ref:`the-request-object` for information on how
the query parameters are accessed.
If a user managed to submit ``/hello?name=<script>alert("bad")</script>``,
escaping causes it to be rendered as text, rather than running the
script in the user's browser.
``<name>`` in the route captures a value from the URL and passes it to
the view function. These variable rules are explained below.
Routing
-------
@ -504,6 +507,8 @@ The other possibility is passing a whole WSGI environment to the
with app.request_context(environ):
assert request.method == 'POST'
.. _the-request-object:
The Request Object
``````````````````