{"id":24021060,"url":"https://github.com/zipcodecore/pyhttp-flask","last_synced_at":"2026-03-03T19:01:38.666Z","repository":{"id":248541419,"uuid":"828975699","full_name":"ZipCodeCore/PyHTTP-Flask","owner":"ZipCodeCore","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-15T14:35:48.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-18T19:23:49.183Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"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/ZipCodeCore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-07-15T13:57:36.000Z","updated_at":"2024-07-15T14:36:46.000Z","dependencies_parsed_at":"2024-07-15T17:38:47.552Z","dependency_job_id":null,"html_url":"https://github.com/ZipCodeCore/PyHTTP-Flask","commit_stats":null,"previous_names":["zipcodecore/pyhttp-flask"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/ZipCodeCore/PyHTTP-Flask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FPyHTTP-Flask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FPyHTTP-Flask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FPyHTTP-Flask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FPyHTTP-Flask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZipCodeCore","download_url":"https://codeload.github.com/ZipCodeCore/PyHTTP-Flask/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZipCodeCore%2FPyHTTP-Flask/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30056056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-01-08T12:38:23.649Z","updated_at":"2026-03-03T19:01:38.635Z","avatar_url":"https://github.com/ZipCodeCore.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyHTTP-Flask\n\nCreate a sinple HTTP server using only Python3.\n\n## Simple HTTP Serverr\n\nCreate a simple HTTP server using Python.\n\n```\npython3 -m http.server\n```\nNow show a static file to the user from this directory.\n\nAdd a simple page.html file to the directory.\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003ctitle\u003ePage\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch1\u003eWelcome to the Page\u003c/h1\u003e\n    \u003cp\u003eThis is a simple page.\u003c/p\u003e\n    \u003ca href=\"https://www.zipcodewilmington.com\"\u003eGo to ZipCode's website\u003c/a\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nNow add a page to the server that displays a message to the user. Make this a file named `page.py`.\n\n```python\nfrom http.server import HTTPServer, BaseHTTPRequestHandler\n\nclass SimpleHTTPRequestHandler(BaseHTTPRequestHandler):\n    def do_GET(self):\n        self.send_response(200)\n        self.end_headers()\n        self.wfile.write(b'Hello, World!')\n\n\nhttpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)\nhttpd.serve_forever()\n```\n\n`Do a GIT triple: Add, Commit, Push` to capture your work.\n\n## Description\nCreate a simple HTTP server using Python and Flask.\n\nCheck out the Flask documentation at https://flask.palletsprojects.com/en/2.0.x/\n\nAnd think of an answer to the following questions:\n\n#### What is Flask?\n#### What is a web framework?\n\nAnd why do you need one?\n\n## Requirements\n\n- in a terminal...make certain you have the following installed:\n- Python 3.8+\n- Flask\n- create a virtual environment using `python3 -m venv .venv`\n- activate the virtual environment using `source .venv/bin/activate`\n- install Flask using `pip install Flask`\n\nTHis is a simple HTTP server using Python. It uses the Flask library to create a simple server that listens on port 5000.\n\n## Usage\n\n\nCreate the contents of the file `app.py`:\n\n```python\nfrom flask import Flask\n\napp = Flask(__name__)\n\n@app.route('/')\ndef zipcode_data():\n    return 'Hello, ZipCode!'\n```\n\nThis will start the web server and you can access it by going to `http://127.0.0.1:5000` in your browser.\n\n`Do a GIT triple: Add, Commit, Push` to capture your work.\n\n## Add two pages to Flask App\n\nThe first page should be a simple HTML page that displays a message to the user. The second page should be a simple form that accepts a user's name and email address. When the user submits the form, the data should be sent to the server and displayed on the form page.\n\n```python\nfrom flask import Flask, render_template, request\n\napp = Flask(__name__)\n\n@app.route('/')\ndef index():\n    return render_template('index.html')\n\n@app.route('/form', methods=['GET', 'POST'])\ndef form():\n    if request.method == 'POST':\n        name = request.form['name']\n        email = request.form['email']\n        return f'Name: {name}, Email: {email}'\n    # else: the request method is GET\n    return render_template('form.html')\n```\n\nFlask is a web framework that makes it easy to build web applications in Python. It provides a simple way to define routes and handle requests. In the example above, we define two routes: one for the index page and one for a form page. The index route returns a simple HTML page, while the form route handles both GET and POST requests. When a POST request is made, it reads the form data and returns a response with the submitted values. When a GET request is made, it returns the form page.\n\n\n`Do a GIT triple: Add, Commit, Push` to capture your work.\n\n## HTML files\n\nThese are the two HTML files that the Flask app uses to display the index and form pages.\n\nindex.html\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003ctitle\u003eIndex\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch1\u003eWelcome to the Index Page\u003c/h1\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nform.html\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003ctitle\u003eForm\u003c/title\u003e\n\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch1\u003eWelcome to the Form Page\u003c/h1\u003e\n    \u003cform action=\"/form\" method=\"post\"\u003e\n        \u003clabel for=\"name\"\u003eName:\u003c/label\u003e\n        \u003cinput type=\"text\" id=\"name\" name=\"name\"\u003e\n        \u003clabel for=\"email\"\u003eEmail:\u003c/label\u003e\n        \u003cinput type=\"email\" id=\"email\" name=\"email\"\u003e\n        \u003cinput type=\"submit\" value=\"Submit\"\u003e\n    \u003c/form\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n`Do a GIT triple: Add, Commit, Push` to capture your work.\n\nNow add a link from the index page to the form page.\n\n```html\n\u003cbody\u003e\n    \u003ch1\u003eWelcome to the Index Page\u003c/h1\u003e\n    \u003ca href=\"/form\"\u003eGo to Form\u003c/a\u003e\n\u003c/body\u003e\n```\n\n`Do a GIT triple: Add, Commit, Push` to capture your work.\n\n#### Perhaps you are starting to see a pattern here??\n\n## Without Flask, pure Python\n\nAnd without Flask, you'd have to write something like this.\nThe amount of code in the two examples is roughly the same, but the Flask code is more readable and easier to understand. And as apps get bigger and more complex, the Flask code will be easier to maintain and extend.\n\n```python\nfrom http.server import BaseHTTPRequestHandler, HTTPServer\nimport urllib.parse as urlparse\n\nclass RequestHandler(BaseHTTPRequestHandler):\n\n    def do_GET(self):\n        if self.path == '/':\n            self.send_response(200)\n            self.send_header('Content-type', 'text/html')\n            self.end_headers()\n            with open('index.html', 'r') as file:\n                self.wfile.write(file.read().encode())\n        elif self.path == '/form':\n            self.send_response(200)\n            self.send_header('Content-type', 'text/html')\n            self.end_headers()\n            with open('form.html', 'r') as file:\n                self.wfile.write(file.read().encode())\n\n    def do_POST(self):\n        if self.path == '/form':\n            content_length = int(self.headers['Content-Length'])\n            post_data = self.rfile.read(content_length)\n            parsed_data = urlparse.parse_qs(post_data.decode())\n\n            name = parsed_data.get('name')[0]\n            email = parsed_data.get('email')[0]\n\n            response = f'Name: {name}, Email: {email}'\n            self.send_response(200)\n            self.send_header('Content-type', 'text/html')\n            self.end_headers()\n            self.wfile.write(response.encode())\n\ndef run(server_class=HTTPServer, handler_class=RequestHandler, port=8000):\n    server_address = ('', port)\n    httpd = server_class(server_address, handler_class)\n    print(f'Server running on port {port}...')\n    httpd.serve_forever()\n\nrun()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzipcodecore%2Fpyhttp-flask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzipcodecore%2Fpyhttp-flask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzipcodecore%2Fpyhttp-flask/lists"}