-2

I am trying to a build a webapp using flask and python. However I received an error code 500 in the Command Prompt. Could anyone please advise? Below is my code and the attached are the error I received. Thanks PS: the website gave me error when I posted my codes in here so I took a snip of my code instead.

from flask import Flask, render_template
from vsearch import search4letters
app = Flask(__name__)
@app.route('/')
def hello() -> str:
    return 'Hello world from Flask!'

@app.route('/search4', methods=['POST'])

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

enter image description here

enter image description here enter image description here enter image description here enter image description here

Long Min
  • 1
  • 1
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Feb 21 '20 at 04:30
  • always put code, data and error message as text. Python can't read image with code and execute it - so we can't test it. – furas Feb 21 '20 at 04:30
  • did you read error message? Error shows you that it can't find `entry.html` - see `TemplateNotFound: entry.html`. Did you put `entry.html` in subfolder `templates` ? – furas Feb 21 '20 at 04:33
  • @furas Thanks for your prompt response. Could you please further explain me about "put entry.html in subfolder templates?" I am not aware of that. Please advise! – Long Min Feb 21 '20 at 04:39
  • flask as default searchs templates (like `entry.html`) inside folder `templates` so you have to create folder `templates` and put `entry.html` in this folder. Read doc: [Templates](https://flask.palletsprojects.com/en/1.1.x/tutorial/templates/) – furas Feb 21 '20 at 04:41
  • @furas, I am learning how to ask questions here the right way. Thanks for your advice! – Long Min Feb 21 '20 at 04:41

1 Answers1

0

In your method for route '/entry', you're trying to render an entry.html, which doesn't exist.

render_template('entry.html', ..

You need to either return some other response or create a file templates/entry.html in the same directory as the file in your post.

Siddhant
  • 573
  • 6
  • 14