[IPython-dev] How to get notebook static url prefix from within python?

Matthias BUSSONNIER bussonniermatthias at gmail.com
Sun Sep 22 08:01:58 EDT 2013


Le 20 sept. 2013 à 21:42, Stephen Chan a écrit :

> Matthias,
>    Thanks for the suggestion. When I try that in a markdown cell and write the output to the console log, it simply returns "/"
> 
>    So, if I were to merely use $('body').data('baseProjectUrl')+'static' is that guaranteed to provide the same url prefix as static_url in the templates?

Hum, I'm not sure it it is guaranteed in the long term, but it will definitively work for now.

>    This also brings up the sticky business of having a script include dependent on the output of another script - if I'm not already using requireJS, I would have to implement a dumbed down imitation of it. It would be better if I could simply get the static_url prefix from within the python backend.

Devil advocate, but js is stored in the document. Can you be certain that your code will always be executed with a non-changing static url ? Also using 'static_url' is already reimplementing part of requireJS...
-- 
M

> 
>    Steve
> 
> 
> On Fri, Sep 20, 2013 at 4:44 AM, Matthias BUSSONNIER <bussonniermatthias at gmail.com> wrote:
> 
> Le 20 sept. 2013 à 02:14, Stephen Chan a écrit :
> 
>>   This seems like it should be easy, but I just don't know the right
>> path through the API and I haven't been having much look googling for
>> it.
>> 
>>   In the notebook.html template, Javascript includes are wrapped by
>> static_url().
>> 
>>   If I have code that generates HTML for display in an output cell,
>> and I want to include JS files from under the static JS directories.
>> It looks like it is in settings.static_url_prefix but don't seem to be
>> able to
>> 
>>   It doesn't show up in the dictionary that get_ipython().config returns.
> 
> $('body').data('baseProjectUrl')
> 
> ?
> 
> I would suggest using require.js (http://requirejs.org/) 
> That is smart enough to know it's own location so that you can load relative url. 
> And also will do all the caching for you if it is needed… help with dependencies… etc
> 
> -- 
> M
> 
> 
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
> 
> 
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev




More information about the IPython-dev mailing list