costapy/README.md

145 lines
4.2 KiB
Markdown
Raw Normal View History

2022-03-16 11:06:52 +07:00
# CostaPy
2022-03-16 10:48:48 +07:00
Python Web Framework. Build with CherryPy and Mako.
2022-03-16 11:06:52 +07:00
## Requirement & Installation
You need this libraries to use CostaPy:
- cherrypy
- mako
- mysql-connector
- bcrypt
You can install it with run this command
sh install.sh
## Usage
Use this command to start the web service
python<ver> costa.py <ip_address> <port> <service_name>
For an example like this
python3 costa.py localhost 80 My_Service
You can use nohup too and running it in the background like this
nohup python3 costa.py localhost 80 My_Service &
## Configuration
### Server (config/server.py)
2022-03-16 11:12:43 +07:00
tools.sessions.on </br>
Default: True </br>
Description: Enable sessions </br>
2022-03-16 11:06:52 +07:00
2022-03-16 11:12:43 +07:00
engine.autoreload.on </br>
Default: False </br>
Description: Auto Reload when source code change. Don't use it in production. </br>
2022-03-16 11:06:52 +07:00
2022-03-16 11:12:43 +07:00
request.show_tracebacks </br>
Default: False </br>
Description: Show traceback for debugging in development purposes. </br>
2022-03-16 11:06:52 +07:00
### Global Variable (config/globalvar.py)
`directory.py` is the place for storing your Global Variable.
2022-03-16 11:12:43 +07:00
GV_base_url </br>
Is the variable for your base URL (without `/` in the end).
2022-03-16 11:06:52 +07:00
2022-03-16 11:12:43 +07:00
GV_title </br>
Is the variable for your web title.
2022-03-16 11:06:52 +07:00
### Directory (config/directory.py)
`directory.py` is the place for storing your path. It is useful to calling the path more efficiently. there is 2 method that you can store your path. store it in variable for templating configuration, and store it as object for routing the url.
This is example that use for templating
html_user = "static/pages-user"
template_user = "static/template-user"
And this is example that use for routing the url
dirconfig = {
'/' :
{
'tools.sessions.on' : True ,
'tools.staticdir.root' : os.path.abspath(os.getcwd()) ,
},
'/your_dir' :
{
'tools.staticdir.on' : True ,
'tools.staticdir.dir' : './static/your-dir' ,
},
}
### Templating (config/template.py)
Templating is useful when you had more than 1 website template for difference use case. For an example, when you had user and admin in the use case, the website for user have a navbar and footer, and the website for admin have a navbar and sidebar.
Before you create a template, make sure your `directory` configuration is ready for storing templates and pages. For an example:
html_user = "static/pages-user"
template_user = "static/template-user"
To create the template, you need to insert this code in `def __init__(self)`
self.html_pages_user = html.main.get_html(directory.html_user)
self.html_template_user = html.main.get_html(directory.template_user)
if you had admin template, you just need to add the code. for the example like this
self.html_pages_user = html.main.get_html(directory.html_user)
self.html_template_user = html.main.get_html(directory.template_user)
self.html_pages_admin = html.main.get_html(directory.html_admin)
self.html_template_admin = html.main.get_html(directory.template_admin)
and then you need create function for each of your template in main class like this
def user(self, page):
params_list = {
"template" : self.html_template_user ["user.html" ] ,
"topnav" : self.html_template_user ["user-topnav.html" ] ,
"container" : self.html_pages_user [page+".html" ]
}
return params_list
### Database (config/database.py)
This is the sample template for configure it
db_default = {
'host' : 'localhost',
'user' : 'root',
'password' : '',
'database' : 'your_db',
'autocommit' : True,
}
You also can make more than 1 database configuration like this
db_default = {
'host' : 'localhost',
'user' : 'root',
'password' : '',
'database' : 'your_db',
'autocommit' : True,
}
db_other = {
'host' : 'localhost',
'user' : 'root',
'password' : '',
'database' : 'other_db',
'autocommit' : True,
}
## Handling the modules
Handling the module is in `handler.py`.