In the same directory, I don’t understand why index.html and the view controller are not automatically bound
. It prompts duck typing. What interferes with the binding of the view?
In this case, app and template are in the same directory, how to write the path?
I wrote it as app =Flask(__name__,template_folder='templates'),
On the left side of pycharm, there is no prompt, templates binds the html icon
By default, templates are in the templates directory at the same level, and your directory has not been created.
The main reason for this is that when the app is defined, it points to the templates directory by default. You should put index.html in the templates directory of rest1.
Or in app=Flask(__name__, template_folder=’path’), specify the path
http://flask.pocoo.org/docs/0... This is the Flask API document
Parameters:
import_name – the name of the application package
static_url_path – can be used to specify a different path for the static files on the web. Defaults to the name of the static_folder folder.
static_folder – the folder with static files that should be served at static_url_path. Defaults to the 'static' folder in the root path of the application.
template_folder – the folder that contains the templates that should be used by the application. .
instance_path – An alternative instance path for the application. By default the folder 'instance' next to the package or module is assumed to be the instance path.
instance_relative_config – if set to True relative filenames for loading the config are assumed to be relative to the instance path instead of the application root.
root_path – Flask by default will automatically calculate the path to the root of the application. In certain situations this cannot be achieved (for instance if the package is a Python 3 namespace package) and needs to be manually defined.
Read the document carefully. It is written that the directory read by the template_folder parameter is based on root_path. You must understand the meaning of each parameter.
pycharm set Mark as template folder