Created
January 29, 2023 11:11
-
-
Save ShimanoN/7017dffc25fb7c12515be0f2203147e4 to your computer and use it in GitHub Desktop.
replace_string.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "94103ca7-239d-42f2-891d-22e7b74486e9", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" * Serving Flask app \"__main__\" (lazy loading)\n", | |
" * Environment: production\n", | |
"\u001b[31m WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n", | |
"\u001b[2m Use a production WSGI server instead.\u001b[0m\n", | |
" * Debug mode: off\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
" * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n", | |
"127.0.0.1 - - [29/Jan/2023 20:02:24] \"GET / HTTP/1.1\" 200 -\n", | |
"127.0.0.1 - - [29/Jan/2023 20:02:24] \"GET /favicon.ico HTTP/1.1\" 404 -\n", | |
"127.0.0.1 - - [29/Jan/2023 20:03:06] \"POST / HTTP/1.1\" 200 -\n" | |
] | |
} | |
], | |
"source": [ | |
"from flask import Flask, request\n", | |
"\n", | |
"app = Flask(__name__)\n", | |
"\n", | |
"@app.route(\"/\")\n", | |
"def index():\n", | |
" return '''\n", | |
" <form method=\"post\">\n", | |
" Enter a string: <input type=\"text\" name=\"original_string\">\n", | |
" <br>\n", | |
" Enter the string you want to replace: <input type=\"text\" name=\"target\">\n", | |
" <br>\n", | |
" Enter the replacement string: <input type=\"text\" name=\"replacement\">\n", | |
" <br>\n", | |
" <input type=\"submit\" value=\"Submit\">\n", | |
" </form>\n", | |
" '''\n", | |
"\n", | |
"@app.route(\"/\", methods=[\"POST\"])\n", | |
"def replace_string():\n", | |
" original_string = request.form[\"original_string\"]\n", | |
" target = request.form[\"target\"]\n", | |
" replacement = request.form[\"replacement\"]\n", | |
" replacement_string = original_string.replace(target, replacement)\n", | |
" return \"Result: \" + replacement_string\n", | |
"\n", | |
"if __name__ == \"__main__\":\n", | |
" app.run()\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "a32a15fb-8c69-4288-8409-dca8d7ec7636", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment