-1

The file structure is at the bottom: [FILE STRUCTURE][1] The error is:
jinja2.exceptions.TemplateNotFound
jinja2.exceptions.TemplateNotFound: entry.html The full error is:
[jinja 2 full error][2]
All files are working except the /entry file (Examine the flask_app code below)
**I am using python version 3 and flask to make a website.I have also imported jinja 2 **

**WARNING: DO NOT COPY PASTE ALL CODE IN ONE FILE.There are different files here.
All files code is given to you


import search4letters

app = Flask(__name__)

@app.route('/search4')
def do_search() -> 'html':
    return str(search4letters('life, the universe, and everything!', 'eiru,!'))
@app.route('/')
@app.route('/entry')
def entry_page() -> 'html':
    return render_template('entry.html', the_title = "Welcome to search4letters on the web!")


app.run(debug=True)

**The entry.html file  code is here: **
{% extends 'base.html' %}
{% block body %}
<h2>{{ the_title }}</h2>
<form method='POST' action='/search4'>
<table>
<p>Use this form to submit a search request:</p>
<tr><td>Phrase:</td><td><input name='phrase' type='TEXT'
width='60'></td></tr>
<tr><td>Letters:</td><td><input name='letters' type='TEXT'
value='aeiou'></td></tr>
</table>
<p>When you're ready, click this button:</p>
<p><input value='Do it!' type='SUBMIT'></p>
</form>
{% endblock %}

###The base.html file code is here: ###
<!doctype html>
<html>
 <head>
 <title>{{ the_title }}</title>
 <link rel="stylesheet" href="static/hf.css" />
 </head>
 <body>
 {% block body %}
 {% endblock %}
 </body>
</html>
  
**I have made the static folder. Inside it is the hf.css file. hf.css file code is given here: **  
body {
    font-family:      Verdana, Geneva, Arial, sans-serif;
    font-size:        medium;
    background-color: grey;
    /* background-color: tan; */
    margin-top:       5%;
    margin-bottom:    5%;
    margin-left:      10%;
    margin-right:     10%;
    border:           1px dotted gray;
    padding:          10px 10px 10px 10px;
  }
  a {
    text-decoration:  none; 
    font-weight:      600; 
  }
  a:hover {
    text-decoration:  underline;
  }
  a img {
    border:           0;
  }
  h2 {
    font-size:        150%;
  }
  table {
    margin-left:      20px;
    margin-right:     20px;
    caption-side:     bottom;
    border-collapse:  collapse;
  }
  td, th {
    padding:          5px;
    text-align:       left;
  }
  .copyright {
    font-size:        75%;
    font-style:       italic;
  }
  .slogan {
    font-size:        75%;
    font-style:       italic;
  }
  .confirmentry {
    font-weight:      600; 
  }
  
  /*** Tables ***/
  
  table {
  font-size:          1em;
  background-color:   #fafcff;
  border:             1px solid #909090;
  color:              #2a2a2a;
  padding:            5px 5px 2px;
  border-collapse:    collapse;
  }
  
  td, th {
  border:             thin dotted gray;
  }
  
  /*** Inputs ***/
  input[type=text] {
    font-size:        115%;
    width:            30em;
  }
  input[type=submit] {
    font-size:        125%;
  }
  select {
    font-size:        125%;
  }```
**Please help me resolve this problem.**
###results.html file code is given here - This file gives the results of to the user.###
{% extends 'base.html' %}
{% block body %}
<h2>{{ the_title }}</h2>
<p>You submitted the following data:</p>
<table>
<tr><td>Phrase:</td><td>{{ the_phrase }}</td></tr>
<tr><td>Letters:</td><td>{{ the_letters }}</td></tr>
</table>
<p>When "{{the_phrase }}" is search for "{{ the_letters }}", the following
results are returned:</p>
<h3>{{ the_results }}</h3>
{% endblock %}


  [1]: https://i.stack.imgur.com/B38GN.png
  [2]: https://i.stack.imgur.com/RIo1H.png

1 Answers1

0

You'll need to ensure all HTML files are placed within a templates folder within your application root directory. Flask structures contain two standard folders, static and templates:

  1. The static folder contains assets used by the templates, including CSS files, JavaScript files, and images.
  2. The templates folder contains only templates. These have an .html extension.

render_template has a default directory to /templates and therefore if the template does not exist within here, you'll receive the TemplateNotFound exception.

General structure layout for a flask application is:

my-flask-app
   ├── static/
   │   └── css/
   │       └── main.css
   ├── templates/
   │   ├── base.html
   │   └── entry.html
   ├── flask_app.py
safe
  • 650
  • 4
  • 13