angel3_jinja

Last updated:

0 purchases

angel3_jinja Image
angel3_jinja Images
Add to Cart

Description:

angel3 jinja

Jinja View Template for Angel3 #




A service that renders Jinja2 view template into HTML for Angel3 framework. Ported from Python to Dart.
Example #
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_jinja/angel_jinja.dart';
import 'package:path/path.dart' as p;

void main() async {
var app = Angel();
var http = AngelHttp(app);
var viewsDir = p.join(
p.dirname(
p.fromUri(Platform.script),
),
'views',
);

// Enable Jinja2 views
await app.configure(jinja(path: viewsDir));

// Add routes.
// See: https://github.com/ykmnkmi/jinja.dart/blob/master/example/bin/server.dart

app
..get('/', (req, res) => res.render('index.html'))
..get('/hello', (req, res) => res.render('hello.html', {'name': 'user'}))
..get('/hello/:name', (req, res) => res.render('hello.html', req.params));

app.fallback((req, res) {
res
..statusCode = 404
..write('404 Not Found :(');
});

// Start the server
await http.startServer('127.0.0.1', 3000);
print('Listening at ${http.uri}');
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.