@@ -107,37 +107,43 @@ Once installed, you can start using the library in your Python projects. Check o
107107## 💻 Usage Examples
108108
109109### Advanced app with flask-like and django-like routes
110- Django-line classes with get-post methods and routing pages:
110+ Django-line classes with get-post methods and routing pages. And with the built-in template engine!
111111
112112``` python
113+ import os
113114from pyechonext.app import ApplicationType, EchoNext
114115from pyechonext.views import View
115116from pyechonext.urls import URL , IndexView
117+ from pyechonext.config import Settings
118+ from pyechonext.template_engine.builtin import render_template
116119
117120
118121class UsersView (View ):
119122 def get (self , request , response , ** kwargs ):
120- return " users get"
123+ return render_template(
124+ request, " index.html" , user_name = " User" , friends = [" Bob" , " Anna" , " John" ]
125+ )
121126
122127 def post (self , request , response , ** kwargs ):
123- return " users post"
128+ return { " users" : " post" }
124129
125130
126- url_patterns = [
127- URL(url = ' /' , view = IndexView),
128- URL(url = ' /users' , view = UsersView)
129- ]
130-
131- echonext = EchoNext(__name__ , urls = url_patterns, application_type = ApplicationType.HTML )
131+ url_patterns = [URL(url = " /" , view = IndexView), URL(url = " /users" , view = UsersView)]
132+ settings = Settings(
133+ BASE_DIR = os.path.dirname(os.path.abspath(__file__ )), TEMPLATES_DIR = " templates"
134+ )
135+ echonext = EchoNext(
136+ __name__ , settings, urls = url_patterns, application_type = ApplicationType.HTML
137+ )
132138
133139
134140@echonext.route_page (" /book" )
135141class BooksResource (View ):
136142 def get (self , request , response , ** kwargs ):
137- return f " Books Page : { request.query_params } "
143+ return f " GET Params : { request.GET } "
138144
139145 def post (self , request , response , ** kwargs ):
140- return " Endpoint to create a book "
146+ return f " POST Params: { request. POST } "
141147```
142148
143149<p align =" right " >(<a href =" #readme-top " >back to top</a >)</p >
@@ -146,14 +152,18 @@ class BooksResource(View):
146152In this example we are using SQLSymphony ORM (our other project, a fast and simple ORM for python)
147153
148154``` python
155+ import os
149156from pyechonext.app import ApplicationType, EchoNext
157+ from pyechonext.config import Settings
150158from sqlsymphony_orm.datatypes.fields import IntegerField, RealField, TextField
151159from sqlsymphony_orm.models.session_models import SessionModel
152160from sqlsymphony_orm.models.session_models import SQLiteSession
153- from sqlsymphony_orm.queries import QueryBuilder
154161
155162
156- echonext = EchoNext(__name__ , application_type = ApplicationType.HTML )
163+ settings = Settings(
164+ BASE_DIR = os.path.dirname(os.path.abspath(__file__ )), TEMPLATES_DIR = " templates"
165+ )
166+ echonext = EchoNext(__name__ , settings, application_type = ApplicationType.HTML )
157167session = SQLiteSession(" echonext.db" )
158168
159169
@@ -170,7 +180,7 @@ class User(SessionModel):
170180
171181@echonext.route_page (" /" )
172182def home (request , response ):
173- user = User(name = ' John' , cash = 100.0 )
183+ user = User(name = " John" , cash = 100.0 )
174184 session.add(user)
175185 session.commit()
176186 response.body = " Hello from the HOME page"
@@ -179,8 +189,9 @@ def home(request, response):
179189@echonext.route_page (" /users" )
180190def about (request , response ):
181191 users = session.get_all_by_model(User)
182-
192+
183193 response.body = f " Users: { [f ' { user.name} : { user.cash} $ ' for user in users]} "
194+
184195```
185196
186197<p align =" right " >(<a href =" #readme-top " >back to top</a >)</p >
0 commit comments