Allowing client-side nbextension to talk to server-side extension

15 views
Skip to first unread message

Ian Stuart

unread,
Feb 23, 2018, 8:02:18 AM2/23/18
to Project Jupyter
Let us assume I have successfully installed a client-side extension that has the following code-fragment:

                            var settings = {
                               url : '/nbu/upload',
                               processData : false,
                               type : "PUT",
                               dataType: "json",
                               data: JSON.stringify(data),
                               contentType: 'application/json',
                               success: function(data) {
           
                                   // display feedback to user

                                    var feedback = '<div class="commit-feedback alert alert-success alert-dismissible" role="alert"> \
                                                     <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> \
                                                     '+data.statusText+' \
                                                      \
                                                   </div>';
           
                                   // display feedback
                                   //$('.commit-feedback').remove();
                                   container.prepend(feedback);
                               },
                               error: function(data) {
           
                                   // display feedback to user
                                   var feedback = '<div class="commit-feedback alert alert-danger alert-dismissible" role="alert"> \
                                                     <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> \
                                                     <strong>Warning!</strong> Something went wrong. \
                                                     <div>'+data.statusText+'</div> \
                                                   </div>';
           
                                   // display feedback
                                   //$('.commit-feedback').remove();
                                   container.prepend(feedback);
                               }
                           }

                            // commit and push
                           utils.ajax(settings);

This extension works fine (notice the use of 'utils.ajax' to call the server to include the XSRF tokens)

On the server-side, I have:
from .handlers import setup_handlers

def load_jupyter_server_extension(nbapp):
    setup_handlers(nbapp.web_app)

and
def setup_handlers(web_app):
    route_pattern = ujoin(web_app.settings['base_url'], '/nbu/upload')
    web_app.add_handlers('.*$', [
        (route_pattern, NbuFileHandler)
    ])

Everything installs correctly - however I'm getting a 'PUT http://localhost:8888/nbu/upload 405 (Method Not Allowed)' error when the ajax call runs.

Any idea why?

Message has been deleted

Ian Stuart

unread,
Feb 23, 2018, 9:00:27 AM2/23/18
to Project Jupyter
Solved!

The definition of the `put` method handler was indented incorrectly, so not seen by the `NbuFileHandler` class

:sigh: - sorry
Reply all
Reply to author
Forward
0 new messages