{"id":17494553,"url":"https://github.com/thakeenathees/localhost","last_synced_at":"2025-04-10T22:23:06.978Z","repository":{"id":106398146,"uuid":"228836303","full_name":"ThakeeNathees/localhost","owner":"ThakeeNathees","description":"A no setup lightweight python web framework -- for localhost","archived":false,"fork":false,"pushed_at":"2019-12-28T21:55:59.000Z","size":839,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T19:21:46.029Z","etag":null,"topics":["bootstrap","localhost","python3","webframework"],"latest_commit_sha":null,"homepage":"","language":"Python","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/ThakeeNathees.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":"2019-12-18T12:32:56.000Z","updated_at":"2024-08-04T08:45:06.000Z","dependencies_parsed_at":"2023-04-12T11:21:50.736Z","dependency_job_id":null,"html_url":"https://github.com/ThakeeNathees/localhost","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/ThakeeNathees%2Flocalhost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThakeeNathees%2Flocalhost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThakeeNathees%2Flocalhost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThakeeNathees%2Flocalhost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThakeeNathees","download_url":"https://codeload.github.com/ThakeeNathees/localhost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248306951,"owners_count":21081761,"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":["bootstrap","localhost","python3","webframework"],"created_at":"2024-10-19T13:27:51.013Z","updated_at":"2025-04-10T22:23:06.968Z","avatar_url":"https://github.com/ThakeeNathees.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# localhost\nA no setup lightweight python web framework -- for localhost\n\n## install\nclone this repository to your python import path and run the below command \n\n```\ngit clone https://github.com/ThakeeNathees/localhost.git\npython localhost init .\npython main.py\n```\nthe command `python localhost init .` creates a python file main.py as below and a directory called server_data\n```python\nfrom localhost import Server\nserver = Server(port=8000)\nserver.run()\n```\n```\nserver_data\n  +-- __init__.py\n  +-- settings.py\n  +-- db/\n  |   +-- auth\n  |         +-- users.csv\n  |         +-- sessions.csv\n  |\n  +-- static/\n  |    +-- css/\n  |    |  +-- bootstrap.min.css\n  |    |  +-- main.css\n  |    +-- html/\n  |    +-- js/\n  |    |   +-- bootstrap.min.js\n  |    |   +-- jquery-3.2.1.slim.min.js\n  |    |   +-- popper.min.js\n  |    +-- image/\n  |\n  +-- templates/\n       +-- localhost/\n            +-- admin/\n            |     +-- home.html\n            |     +-- login.html\n            |     +-- logout.html\n            +-- base.html\n            +-- home.html\n            +-- error.html\n```\n\nnow the server will run at `http://www.localhost:8000/` and you'll see the localhost default home page (for the admin page : localhost:8000/admin)\n\n## screenshot\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"screenshot.jpg\" width=\"1000\" align=\"middle\"\u003e\n\u003c/p\u003e\n\n## url routing\nTo add your url paths\n```python\nfrom localhost import Server\nfrom localhost.urls import path \nfrom localhost.response import HttpResponse\n\nserver = Server(port=8000)\n\ndef home_view(request):\n  return HttpResponse('\u003ch1\u003ewelcome to the home page!!!\u003c/h1\u003e')\n  \nurlpatterns = [\n  path('/home',  home_view, name='home-page')\n]\n\nserver.urlpatterns = urlpatterns\n\nserver.run()\n```\n\n## render html\nInstead of HttpResponse you can return a rendered html page.\u003cbr\u003e\n\nin the settings.py the default path for the templates are specified as  \n```TEMPLATE_DIR = os.path.join(SERVER_DATA_DIR, 'templates')```\n\ncreate your home-page template (home.html) in your TEMPLATE_DIR\n\n```html\n{{ html_base_begin }}\n\u003c!-- headers, open \u003cbody\u003e tag, boostrap style shees --\u003e \n\n\u003cdiv class=\"container\" style=\"margin-top:50px\"\u003e\n\n \u003cdiv class=\"alert alert-success\" role=\"alert\"\u003e\n  \u003ch4 class=\"alert-heading\"\u003eWelcome!!!\u003c/h4\u003e\n  \u003cp\u003e With localhost using \"html_base_begin\" and \"html_base_end\" context you can use boostrap, \n    and a simple html layout, all you have to write here is the body of the page.\n  \u003c/p\u003e\n  \u003chr\u003e\n  {{ replace_me }}\n  \u003c/div\u003e\n\n\u003c/div\u003e\n\n \u003c!-- close \u003c/body\u003e tag, bootstrap javascript files --\u003e\n{{ html_base_end }}\n```\nnow render the template\n```python\nfrom localhost.response import render\ndef home_view(request):\n    return render(request, 'home.html', ctx={\n        'replace_me':'\u003cp class=\"mb-0\"\u003eyou can use context to replace with html source code\u003c/p\u003e'\n    })\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthakeenathees%2Flocalhost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthakeenathees%2Flocalhost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthakeenathees%2Flocalhost/lists"}