2

I have used pyramid to write a project. In a html page of the project, i want to use a button to call a python script, the python script is located in the path "myapp/Script".

I have this method tried but it dosn't work:

<script Language="javascript">
    function call() {
        http://localhost/Scripts/xxx.py
    }
</script>

Thank you very much! :)

0

1 Answer 1

2

In most scenarios, the communicating from JavaScript to server-side is done using AJAX. Furthermore, most sites use jQuery JavaScript library to make AJAX programming easier.

AJAX requests are handled like any other HTTP requests in Pyramid.

  1. Write a view in Pyramid (this is the "python script" part)

  2. Map this view to URL

  3. Include jQuery library on your HTML page

  4. Then call it through AJAX

    <script>
        function call() {
            $.ajax("/myurl/", function(result) {
                console.log("I got this response from the server ", result)
            });
        }
    </script>
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.