Drew Verlee
Drew Verlee

Reputation: 1900

How to use pyjade as part of clientside and serverside application?

I'm creating a single page application using flask. If I understand the process correctly, then ill be having flask serve up a single page (html and css) upon the first GET request. From their, the client will only receive data and the it will use already stored html (partials/other pages) to modify the site.

Ideally, I would like to use something that provides a nicer syntax then html, something like slim, haml or jade. Though i don't need the templating aspect, as this functionality will be provided through angularJS.

Assuming the above is correct, my confusion is how to use pyjade (or any such tool) with flask to transform the partials that the client side application would be using. For example, if i have some client side code that creates the routes like so...

var app = angular.module('App');

app.config(function($routeProvider){
    $routeProvider.when('/', {
        templateURL: 'partials/home.jade',
        controller: 'HomeController'    
    }).otherwise({ redirectTo: '/' });
});

Then i would need home.jade to be transformed into home.html when it was served up to the client. Assuming I understand what 'should' be done correctly, how do I do this?

One such solution would be manually transform the home.jade into home.html and keep my code like this:

var app = angular.module('App');

    app.config(function($routeProvider){
        $routeProvider.when('/', {
            templateURL: 'partials/home.jade',
            controller: 'HomeController'    
        }).otherwise({ redirectTo: '/' });
    });

Upvotes: 0

Views: 148

Answers (1)

cjohnson318
cjohnson318

Reputation: 3253

I'm using Flask, PyJade, and jQuery as a controller. You can install PyJade with,

sudo pip install pyjade

And then according to the documentation you can insert the following line in your Flask app,

app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')

Upvotes: 0

Related Questions