使用python代码

时间:2017-08-06 05:13:26

标签: javascript python

我正在尝试使用python后端自动创建应用的重复代码。我希望用python脚本将几行javascript代码添加到js文件中。有人可以指导我吗?

我的代码如下所示:

angular.module('app').config(['$routeProvider',
function($routeProvider) {
    $routeProvider
        .when('/', {
            templateUrl: '/static/partials/home.html',
            controller: 'HomeController'
        })
        .when('/hello', {
            templateUrl: '/static/partials/hello.html',
            controller: 'HelloController'
        })
    }
]);

我想从后端动态添加另一个url'/ index',这是在python中。

因此,在添加代码后,它应如下所示:

angular.module('app').config(['$routeProvider',
function($routeProvider) {
    $routeProvider
        .when('/', {
            templateUrl: '/static/partials/home.html',
            controller: 'HomeController'
        })
        .when('/hello', {
            templateUrl: '/static/partials/hello.html',
            controller: 'HelloController'
        })
        .when('/index', {
            templateUrl: '/static/partials/index.html',
            controller: 'IndexController'
        })
    }
]);  

1 个答案:

答案 0 :(得分:0)

你可以使用它。

f = open("<<path of your js file>>.js", 'b')
f.write("console.log('it works');")
f.close()

&#39;&#39;是开放功能运作的模式

模式是&#39; r&#39;阅读,&#39; w&#39;用于写入(截断文件,如果它已经存在),以及&#39; a&#39;附加

请参阅下面的python文档。

https://docs.python.org/2/library/functions.html#open