How to access local file in Flask? [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
How to serve static files in Flask
13 answers
I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.
File directory:
-Flask
-static/
--some js
-template/
--some HTML
-logs/
--log1.log
--log2.log
--...
app.py
I access the file in HTML as
localhost:port/logs/log1.log
But the web gives me a 404.
How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?
Thanks.
flask routes
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 4 at 14:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to serve static files in Flask
13 answers
I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.
File directory:
-Flask
-static/
--some js
-template/
--some HTML
-logs/
--log1.log
--log2.log
--...
app.py
I access the file in HTML as
localhost:port/logs/log1.log
But the web gives me a 404.
How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?
Thanks.
flask routes
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 4 at 14:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to serve static files in Flask
13 answers
I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.
File directory:
-Flask
-static/
--some js
-template/
--some HTML
-logs/
--log1.log
--log2.log
--...
app.py
I access the file in HTML as
localhost:port/logs/log1.log
But the web gives me a 404.
How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?
Thanks.
flask routes
This question already has an answer here:
How to serve static files in Flask
13 answers
I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.
File directory:
-Flask
-static/
--some js
-template/
--some HTML
-logs/
--log1.log
--log2.log
--...
app.py
I access the file in HTML as
localhost:port/logs/log1.log
But the web gives me a 404.
How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?
Thanks.
This question already has an answer here:
How to serve static files in Flask
13 answers
flask routes
flask routes
asked Jan 4 at 4:54
Elegant LinElegant Lin
62
62
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 4 at 14:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 4 at 14:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use send_from_directory function in flask to send static files
This might help you
@app.route('/logs/<path:filename>')
def download_file(filename):
return send_from_directory("/logs/",
filename, as_attachment=True)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use send_from_directory function in flask to send static files
This might help you
@app.route('/logs/<path:filename>')
def download_file(filename):
return send_from_directory("/logs/",
filename, as_attachment=True)
add a comment |
You can use send_from_directory function in flask to send static files
This might help you
@app.route('/logs/<path:filename>')
def download_file(filename):
return send_from_directory("/logs/",
filename, as_attachment=True)
add a comment |
You can use send_from_directory function in flask to send static files
This might help you
@app.route('/logs/<path:filename>')
def download_file(filename):
return send_from_directory("/logs/",
filename, as_attachment=True)
You can use send_from_directory function in flask to send static files
This might help you
@app.route('/logs/<path:filename>')
def download_file(filename):
return send_from_directory("/logs/",
filename, as_attachment=True)
answered Jan 4 at 7:02
Deepam PatelDeepam Patel
1015
1015
add a comment |
add a comment |