Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-server

A Basic Python Server

Complete vanilla python server, no external libraries required

Basic Features

  1. Static Server
  2. Controllers
  3. Templates
  4. SMTP Emailer
  5. XHR (POST)
  6. XHR (GET)

install & init

git clone https://github.com/mooioom/python-server

And then...

python server.py <port>

Server is running on port 80 (default)

routes.json

Use routes.json to define routes

[
    {
        "uri" : "/controller",
        "controller" : "basic_controller"   // points to 'ctrl' folder
    }
]

Templating

Data can be passed to HTML templates using double-curlies {{}}

basic_template.html

<div>
    Hello {{name}}, How Are You?
</div>

ctrl/basic.py

def default( server ):
    content = server.template( 'basic_template', { 'name' : 'David' } )
    server.respond( content )

call API - public/js/api.js

This contains a basic call function to XHR the server

call( action_name, callback, data )

including the API :
<script src="__public/js/api.js" /></script>

Example :

call('login', r => {

    if( r ) location.reload();
    
}, {
    username : '',
    password : ''
})

Emailer

The SMTP emailer can be defined on server.py (defaults to Gmail)

Example :

SMTP_HOST = 'smtp.gmail.com'
SMTP_PORT = 465

TODOs

Some basic features left to complete

  • Todo :: Sessions

About

Python Server

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages