I am trying to use jquery .load in my flask app to add a div every time the user presses a button to add a new div, but it can't find the html file.
The function in question.
$(document).ready(function(){
$("#add").click(function(){
$("#form").load('/templates/info.html');
})
});
The info.html file only hold a short div section of html.
index.html the code, where I want to load the info.html div after the form.
<form id="form" action="{{ url_for('get_data') }}" method="post">
<input type="button" name="add" value="Add" id="add">
<input type="submit" id="submit" value="To XML">
</form>
/templates/info.html
<div id="info">
<label>name</label>
<input type="text" name="name">
<br>
<label>asfd</label>
<input type="text" name="asfd">
<br>
</div>
I keep getting this 404 error.
127.0.0.1 - - [04/Mar/2014 19:55:50] "GET /templates/info.html HTTP/1.1" 404 -
I am running the flask app locally, and /template/info.html is the correct path. I just don't know why it doesn't load in that html. I am able to make it work when I use the jquery function and .append() and put the long html string into the append function, but add the info.html gets longer I just want to be able to load the whole file.
Any help would be great thanks.
templatesis just a folder. Flask doesn't serve the contents unless you explicitly ask it to. Setup a route (@route('/info')or something similar), render the template, and request/infoinstead of that URL./templates/info.html. From there, it's entirely up to Flask to determine what/templates/info.htmlactually means. It could just send back the URL in reverse as a response. Flask doesn't serve the contents of/templates/the same way it does for/static/, which might be a better choice for you (although I would suggest instead to make a route that actually renders the template, as in the below answer, and use jQuery to load it)./static/instead of/templates/.