https://github.com/thakeenathees/localhost
A no setup lightweight python web framework -- for localhost
https://github.com/thakeenathees/localhost
bootstrap localhost python3 webframework
Last synced: 11 months ago
JSON representation
A no setup lightweight python web framework -- for localhost
- Host: GitHub
- URL: https://github.com/thakeenathees/localhost
- Owner: ThakeeNathees
- License: mit
- Created: 2019-12-18T12:32:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-28T21:55:59.000Z (about 6 years ago)
- Last Synced: 2025-03-24T19:21:46.029Z (11 months ago)
- Topics: bootstrap, localhost, python3, webframework
- Language: Python
- Homepage:
- Size: 819 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# localhost
A no setup lightweight python web framework -- for localhost
## install
clone this repository to your python import path and run the below command
```
git clone https://github.com/ThakeeNathees/localhost.git
python localhost init .
python main.py
```
the command `python localhost init .` creates a python file main.py as below and a directory called server_data
```python
from localhost import Server
server = Server(port=8000)
server.run()
```
```
server_data
+-- __init__.py
+-- settings.py
+-- db/
| +-- auth
| +-- users.csv
| +-- sessions.csv
|
+-- static/
| +-- css/
| | +-- bootstrap.min.css
| | +-- main.css
| +-- html/
| +-- js/
| | +-- bootstrap.min.js
| | +-- jquery-3.2.1.slim.min.js
| | +-- popper.min.js
| +-- image/
|
+-- templates/
+-- localhost/
+-- admin/
| +-- home.html
| +-- login.html
| +-- logout.html
+-- base.html
+-- home.html
+-- error.html
```
now 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)
## screenshot
## url routing
To add your url paths
```python
from localhost import Server
from localhost.urls import path
from localhost.response import HttpResponse
server = Server(port=8000)
def home_view(request):
return HttpResponse('
welcome to the home page!!!
')
urlpatterns = [
path('/home', home_view, name='home-page')
]
server.urlpatterns = urlpatterns
server.run()
```
## render html
Instead of HttpResponse you can return a rendered html page.
in the settings.py the default path for the templates are specified as
```TEMPLATE_DIR = os.path.join(SERVER_DATA_DIR, 'templates')```
create your home-page template (home.html) in your TEMPLATE_DIR
```html
{{ html_base_begin }}
Welcome!!!
With localhost using "html_base_begin" and "html_base_end" context you can use boostrap,
and a simple html layout, all you have to write here is the body of the page.
{{ replace_me }}
{{ html_base_end }}
```
now render the template
```python
from localhost.response import render
def home_view(request):
return render(request, 'home.html', ctx={
'replace_me':'
you can use context to replace with html source code
'
})
```