Merge branch 'master' of https://github.com/channelcat/sanic
This commit is contained in:
		| @@ -9,6 +9,8 @@ On top of being Flask-like, Sanic supports async request handlers.  This means y | ||||
|  | ||||
| Sanic is developed `on GitHub <https://github.com/channelcat/sanic/>`_. Contributions are welcome! | ||||
|  | ||||
| If you have a project that utilizes Sanic make sure to comment on the `issue <https://github.com/channelcat/sanic/issues/396>`_ that we use to track those projects! | ||||
|  | ||||
| Benchmarks | ||||
| ---------- | ||||
|  | ||||
|   | ||||
| @@ -1,15 +1,16 @@ | ||||
| # Render templates in a Flask like way from a "template" directory in the project | ||||
| # Render templates in a Flask like way from a "template" directory in | ||||
| # the project | ||||
| 
 | ||||
| from sanic import Sanic | ||||
| from sanic import response | ||||
| from jinja2 import Evironment, PackageLoader, select_autoescape | ||||
| from jinja2 import Environment, PackageLoader, select_autoescape | ||||
| 
 | ||||
| app = Sanic(__name__) | ||||
| 
 | ||||
| # Load the template environment with async support | ||||
| template_env = Environment( | ||||
|     loader=jinja2.PackageLoader('yourapplication', 'templates'), | ||||
|     autoescape=jinja2.select_autoescape(['html', 'xml']), | ||||
|     loader=PackageLoader('jinja_example', 'templates'), | ||||
|     autoescape=select_autoescape(['html', 'xml']), | ||||
|     enable_async=True | ||||
| ) | ||||
| 
 | ||||
| @@ -19,9 +20,9 @@ template = template_env.get_template("example_template.html") | ||||
| 
 | ||||
| @app.route('/') | ||||
| async def test(request): | ||||
|     data = request.json | ||||
|     rendered_template = await template.render_async(**data) | ||||
|     rendered_template = await template.render_async( | ||||
|         knights='that say nih; asynchronously') | ||||
|     return response.html(rendered_template) | ||||
| 
 | ||||
| 
 | ||||
| app.run(host="0.0.0.0", port=8080, debug=True) | ||||
| app.run(host="0.0.0.0", port=8080, debug=True) | ||||
							
								
								
									
										8
									
								
								examples/jinja_example/requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								examples/jinja_example/requirements.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| aiofiles==0.3.1 | ||||
| httptools==0.0.9 | ||||
| Jinja2==2.9.6 | ||||
| MarkupSafe==1.0 | ||||
| sanic==0.5.2 | ||||
| ujson==1.35 | ||||
| uvloop==0.8.0 | ||||
| websockets==3.3 | ||||
							
								
								
									
										10
									
								
								examples/jinja_example/templates/example_template.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								examples/jinja_example/templates/example_template.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
|     <title>My Webpage</title> | ||||
| </head> | ||||
| <body> | ||||
|     <h1>Hello World</h1> | ||||
|     <p>knights - {{ knights }}</p> | ||||
| </body> | ||||
| </html> | ||||
		Reference in New Issue
	
	Block a user
	 zenix
					zenix