costa-vite-myna/README.md

172 lines
5.0 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
2022-03-16 11:22:14 +07:00
## License
CostaPy
Copyright (C) 2022 Dita Aji Pratama
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
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
2022-06-14 14:50:07 +07:00
Here is the completed command
pip install --upgrade pip
pip install cherrypy
pip install mako
pip install mysql-connector
pip install bcrypt
2022-03-16 11:06:52 +07:00
## 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`.