Python - Flask: render_template() not found
You put your template in the wrong place. From the Flask docs:
Flask will look for templates in the templates folder. So if your application is a module, this folder is next to that module, if it’s a package it’s actually inside your package:
See the docs for more information: http://flask.pocoo.org/docs/quickstart/#rendering-templates
`app.route` and `template_render` not working in Flask
Finally I managed to solve this issue .
The problem was 1st I runned this code via PyCharm and then by Python interpreter IDLE (obviously after closing pyCharm) and somehow PyCharm was still controlling the server even after system restart .
So after checking everything and getting now clue I just powered off my system completely and started again and then run the application via IDLE only thus solving all issue !
So the conclusion was :
->PyCharm was still controlling the server even after system restart.
->Power off and on solved the issue for me .
Sounds weird but that's how it worked .
If anyone here can explain why PyCharm was still controlling servers even after restart would be better .
Flask render_template() does not render the xhtml, but it renders correctly in my browser when I open it manually
Both files are very similar, because the secound file is just a modification of the first file using BeatifulSoup. I played around with the files and changed codeblocks step by step. I figured out, that BeautifulSoup changed
<Viewpoint ... ></Viewpoint>
to
<Viewpoint ... />
and jinja does not seem to like it. After changing those tags in the broken file it now gets rendered correctly:
<Viewpoint ... > </Viewpoint>
Even though noone could solve that Problem for me, I am still thankful for your input, as it got me thinking about my Problem more focussed.
Flask render_template() not being called after client POST with data
It is because you are returning the template within the handling of a POST request. You are actually parsing the template as a response to the client instead of as a page to be rendered. Instead, I recommend you to redirect to another view function to display the error with a GET request from the client side, which you pass the error_output
to as a value of a query string. If you need to run some logic on the output beforehand, you can keep the original view function error
. Else, you can just make use of the new one display_error
, without having to go through the first one.
@app.route('/run_error/', methods=['POST'])
def error():
if request.method = 'POST':
request_json = request.json
error_output = request_json['data']
return json.dumps({'error_output': error_ouput})
@app.route('/display_error/', methods=['GET'])
def display_error():
error_output = request.args.get('error_output')
return render_template('run_error.html', error_output=error_output)
The client side will then after a successfull post request (or without it) redirect to the display_error
view function and pass error_output
as a parameter:
.then(response => response)
.then(
console.log('Success:', sent_data);
var response = JSON.parse(response);
var error_output = response["error_output"];
window.location.href = "/display_error/?error_output="+error_output;
);
Python Flask not displaying contents with render_template()
In base.html change {% block content %}
to {% block body %}
<div id="container">
<!-- Jinja directives: page contents will go between them -->
{% block body %}
{% endblock %}
</div>
Related Topics
Retrieve Top N in Each Group of a Dataframe in Pyspark
Psycopg2 Insert Python Dictionary as Json
Write a Program That Find the Largest Integer in a String
Using Pyserial to Send Binary Data
How to Pass a Dictionary Object as Parameter for a Function in Python
Index Out of Bounds Error:Python
How to Build Reports With Python Pandas
Count Unique Words in a Text File (Python)
Implement K-Fold Cross Validation in Mlpclassification Python
How to Change the File Name of an Uploaded File in Django
Python - How to Check If Table Exists
How to Further Filter a Result of Resultset
Interactive Matplotlib Figures in Google Colab
Best Way to Identify and Extract Dates from Text Python
Convert Timedelta to Floating-Point
Jupyter Notebook, Python3 Print Function: No Output, No Error