{"id":22688334,"url":"https://github.com/emanuelefavero/flask","last_synced_at":"2026-05-09T10:37:30.288Z","repository":{"id":69309449,"uuid":"604411802","full_name":"emanuelefavero/flask","owner":"emanuelefavero","description":"This is a cheat sheet repo for Flask (Python web framework)","archived":false,"fork":false,"pushed_at":"2023-02-21T05:58:43.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-04T16:50:32.590Z","etag":null,"topics":["flask","python","server","wsgi"],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emanuelefavero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-21T02:12:13.000Z","updated_at":"2023-07-22T16:08:30.000Z","dependencies_parsed_at":"2023-04-08T21:53:26.613Z","dependency_job_id":null,"html_url":"https://github.com/emanuelefavero/flask","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Fflask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Fflask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Fflask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Fflask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emanuelefavero","download_url":"https://codeload.github.com/emanuelefavero/flask/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246207509,"owners_count":20740723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","python","server","wsgi"],"created_at":"2024-12-10T00:13:58.190Z","updated_at":"2026-05-09T10:37:30.220Z","avatar_url":"https://github.com/emanuelefavero.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask\n\nThis is a cheat sheet repo for [Flask](https://flask.palletsprojects.com/en/2.2.x/)\n\n\u003e Flask is a lightweight Python [WSGI](https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface?useskin=vector) (Web Server Gateway Interface) web application framework. It is similar to Express.js in Node.js\n\n## Installation for both new projects and cloned repos\n\n- Create a virtual environment\n\n```bash\nmkdir myproject\ncd myproject\npython3 -m venv venv\n```\n\n\u003e use `py -3 -m venv venv` on Windows\n\n- Activate the virtual environment\n\n```bash\n. venv/bin/activate\n```\n\n\u003e use `venv\\Scripts\\activate` on Windows\n\n- Install Flask\n\n```bash\npip install Flask\n```\n\n## Quickstart\n\n- Create a file called `app.py` with the following content:\n\n```python\nfrom flask import Flask\n\napp = Flask(__name__)\n\n@app.route(\"/\")\ndef hello_world():\n    return \"\u003cp\u003eHello, World!\u003c/p\u003e\"\n```\n\n- Run the app\n\n```bash\nflask --app app run --debug\n```\n\n\u003e To allow access to other devices on the network, use `--host=0.0.0.0`\n\n## Pass variables\n\n```python\n...\ndef hello_name():\nname = 'John'\nreturn f\"Hello {name}!\"\n\n```\n\n## HTTP Methods\n\n```python\n# HTTP METHODS\n@app.route(\"/login\", methods=[\"GET\", \"POST\"])\ndef login():\n    if request.method == \"POST\":\n        # DO THE LOGIN STUFF\n        return \"You are now logged in\"\n    else:\n        # SHOW THE LOGIN FORM\n        return \"Please log in\"\n```\n\n## URL Parameters\n\n```python\n# URL PARAMETERS\n# specify the type using converters: \u003cint:variable_name\u003e\n# converters: int, float, path, uuid\n@app.route(\"/user/\u003cname\u003e\")\ndef user(name):\n    return f\"Hello {name}\"\n```\n\n## Static files\n\n- Add a folder called static to the root of the project\n- Add a file called `style.css` to the static folder\n- Reference that file in the HTML\n\n```html\n\u003clink rel=\"stylesheet\" href=\"{{ url_for('static', filename='style.css') }}\" /\u003e\n```\n\n## Template Engine (Jinja2)\n\n- Create a folder called `templates` in the root of the project\n- Create a file called `index.html` in the templates folder\n- Render the template in the view\n\n```python\nfrom flask import render_template\n\n@app.route(\"/\")\ndef index():\n  name = \"John\"\n    return render_template(\"index.html\", title=\"Home\", name=name)\n```\n\n## Link between pages\n\n```html\n\u003ca href=\"{{ url_for('index') }}\"\u003eHome\u003c/a\u003e\n```\n\n\u003e Note: `index` is the name of the view function\n\n## Resources\n\n- [Flask Documentation](https://flask.palletsprojects.com/en/2.2.x/)\n- [WSGI](https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface?useskin=vector)\n- [Python](https://www.w3schools.com/python/)\n\n## License\n\n- [MIT](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuelefavero%2Fflask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femanuelefavero%2Fflask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuelefavero%2Fflask/lists"}