Complete vanilla python server, no external libraries required
- Static Server
- Controllers
- Templates
- SMTP Emailer
- XHR (POST)
- XHR (GET)
git clone https://github.com/mooioom/python-server
And then...
python server.py <port>
Server is running on port 80 (default)
Use routes.json to define routes
[
{
"uri" : "/controller",
"controller" : "basic_controller" // points to 'ctrl' folder
}
]
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 )
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 : ''
})
The SMTP emailer can be defined on server.py (defaults to Gmail)
Example :
SMTP_HOST = 'smtp.gmail.com'
SMTP_PORT = 465
Some basic features left to complete
- Todo :: Sessions