I am trying to figure out how to configure the base url of and IPython notebook server running. So instead of the default:
#request# GET http://localhost:8888/static/tree/js/main.min.js?v=04a28c5e21950738efb217191f08ac33
#request# GET http://localhost:8888/api/terminals?_=1441754529652
#request# GET http://localhost:8888/custom/custom.js?v=20150908160654
#request# GET http://localhost:8888/notebooks/Untitled1.ipynb?kernel_name=python3#
I want to configure all requests so that the go through ipython, as in:
#request# GET http://localhost:8888/ipython/static/tree/js/main.min.js?v=04a28c5e21950738efb217191f08ac33
#request# GET http://localhost:8888/ipython/api/terminals?_=1441754529652
#request# GET http://localhost:8888/ipython/custom/custom.js?v=20150908160654
#request# GET http://localhost:8888/ipython/notebooks/Untitled1.ipynb?kernel_name=python3#
Is this possible?
To change the base url for the files that are being served up from iPython, edit the ipython_notebook_config.py file in your ~/.ipython/[profile-name]/ directory.
In particular, assuming that your config file starts with the line c = get_config(), you will want to add the following lines to your configuration:
c.NotebookApp.base_project_url = '/ipython/'
c.NotebookApp.base_kernel_url = '/ipython/'
c.NotebookApp.webapp_settings = {'static_url_prefix':'/ipython/static/'}
This will make it so that your project is served up from http://localhost:8888/ipython/ instead of http://localhost:8888/.
For more information please see this page of the ipython docs.
Related
I am trying to load a torrent file into rtorrent using xmlrpc with the following python3 code:
import xmlrpc.client
server_url = "https://%s:%s#%s/xmlrpc" % ('[REDACTED]', '[REDACTED]', '[REDACTED]');
server = xmlrpc.client.Server(server_url);
with open("test.torrent", "rb") as torrent:
server.load.raw_verbose(xmlrpc.client.Binary(torrent.read()),"d.delete_tied=","d.custom1.set=Test","d.directory.set=/home/[REDACTED]/files")
The load_raw command returns without an error (return code 0), but the torrent does not appear in the rutorrent UI. I seem to be experiencing the same thing as from this reddit post, but I am using the Binary class without any luck.
I am using a Whatbox seedbox.
EDIT:
After enabling logging I am seeing
1572765194 E Could not create download, the input is not a valid torrent.
when trying to load the torrent file, however manually loading the torrent file through the rutorrent UI works fine.
I needed to add "" as the first argument:
server.load.raw_verbose("",xmlrpc.client.Binary(torrent.read()),"d.delete_tied=","d.custom1.set=Test","d.directory.set=/home/[REDACTED]/files")
Not sure why, the docs don't seem to show this is needed.
I get the following error message in browser console when I try to integrate my angular front end with django.
GET http://127.0.0.1:8000/assets/another.js 404 (Not Found)
I believe I have configured static file settings in django correctly as it is able to locate all the other static files, ie main.js, polyfills.js, vendor.js etc.
This assets/another.js call initiated by vendor.js while other js files are called in index.html. I have all these files in the same static dir.
When I run python manage.py findstatic --verbosity 2 assets/another.js I get the following response -
Found 'assets/another.js' here:
/home/path/to/project/server/static/assets/another.js
Looking in the following locations:
/home/path/to/project/server/server/static
/home/path/to/admin/static # irrelevant in this case
So I am using python flask to develop a web application that asks the user for data, analyse the data in the backend using BLAST and R, and outputs interactive HTML plots that are stored in a local location (Templates) and to be displayed to the user.
Everything up to R outputs runs smoothly. I have opened the HTML files and confirmed the R codes ran as expected and the produced graphs are interactive. However when I render these HTMLs through flask the browser returns a black page. Using send_file was also fruitless to display the plots. I have confirmed that the path to the Java scripts for the interactive plot are in the same folder.
Going through the developers tool console reads the following error:
htmlwidgets.js:1 Uncaught SyntaxError: Unexpected token <
jquery.min.js:1 Uncaught SyntaxError: Unexpected token <
datatables.js:1 Uncaught SyntaxError: Unexpected token <
jquery.dataTables.min.js:1 Uncaught SyntaxError: Unexpected token <
Can someone please advise on how to successfully get the interactive R HTML outputs to show in flask?
When you use send_file or send_from_directory you would also need to serve the JavaScript libraries needed for the plot, this might be the reason for the blank page.
The same is true for render_template but according to the error messages it seems more like that your JS libraries were also rendered as templates and some < or > character got added or removed.
Try the following snippet which works for me and perhaps gives you a good start.
A very simple R script to create a standalone HTML file with a Plotly plot. A file called test.html is created in the /tmp directory. All JavaScript libraries and CSS files are in /tmp/test_files.
library(plotly)
library(htmlwidgets)
myData <- data.frame(x=c(1,2,3), y=c(3,2,1))
local_path <- '/tmp/'
ply <- plot_ly(myData, x = ~x, y = ~y, type='scatter', mode='markers+line')
saveWidget(widget=ply, file=paste(local_path, "test.html", sep=""), selfcontained = FALSE)
A minimal Flask server snippet to serve the plot and the JavaScript libraries is below. Starting flask and going in the browsesr to http://localhost:5000/ would show the plot and provide all need libraries.
from flask import Flask
from flask import send_from_directory
app = Flask(__name__)
#app.route('/')
def plotly():
return send_from_directory('/tmp/', 'test.html')
#app.route('/test_files/<path:path>')
def send_js(path):
return send_from_directory('/tmp/test_files', path)
So I have the following environment; django 1.8. apache on ubuntu 14 with mod_wsgi and mod x-sendfile enabled.
I have a very simple view to server the files as follows:
def foo(request, filename):
response = HttpResponse()
response['Content-Disposition'] = 'attachment; filename={0}'.format(filename)
response['X-Sendfile'] = "/home/amir/DjV/Files/{0}".format(filename)
return response
and here's my urlconf regarding the view:
url(r'^foo/(.+)/$', foo)
I've written a snippet that generate absolute path to files to be presented in a download list. The generated paths work fine if I enter them in the browser; but if I use them as hyperlinks, when clicked it goes to blank page. For examlple here is one the urls that is generated by the snippet I mentioned:
http://192.168.43.6:8000/foo/uuid.txt
it works fine and I get to download the uuid.txt, but when I put it into django template as follows, it doesn't work:
192.168.43.6:8000/foo/uuid.txt
My question being: why my link works fine when entered manually but not when used as a hyperlink? Could it be because of being a local address? How can I fix it?
You need to specify a protocol inside your template when doing such things:
192.168.43.6:8000/foo/uuid.txt
However, you should not hard code urls in this way in special not if they are handled inside your Django application. Check {% url %} templating whether it could be a benefit for you
I can locally visit my picture, but when I want my visit from my django server there is always error.
the source code:
from django.http.response import HttpResponse
import mimetypes
fd = open(CONFIG.SERVICES_PATH + sname+'/'+url,'r')
print CONFIG.SERVICES_PATH + sname+'/'+url
mime_type_guess = mimetypes.guess_type(url)
print mime_type_guess
data = fd.read()
fd.close()
response = HttpResponse(data,mimetype = mime_type_guess[0])
the print out on console is:
E:/workspace/sydney/main/services/Hunt-Club/shop/1.jpg
('image/pjpeg', None)
I can visit the picture from local path, but when I run the django server and visit from browser it gives me errors:
http://localhost:8000/gallery/image/Hunt-Club/shop/1/” cannot be displayed because it contains errors.">
I do not know want I give correct path and read the data, there is still error for picture require.
You may want to rethink serving files through the django app.
Instead you should serve them from /static folder which in an apache setup you would configure using an alias.
That being said, check this out: image/pjpeg and image/jpeg
It says it may have something to do with serving pjpeg content-type to IE.
Hope that helps.
i find where my error is, the read image file code should be:
fd = open(CONFIG.SERVICES_PATH + sname+'/'+url,'rb')
Because in windows open file default applying open in ASCII, so the file doesn't read properly.