Webview not available for Flask repl

Hi, I can’t see Webview for this Flask repl - https://replit.com/@CatherineMelo/MVPtruebuild

When I was doing Day 77 of the 100 days of Python, Webview shows up no problem. I’ve pasted the code from my repl to the Day77 one but it also doesn’t run. What do I need to do?

Hi @CatherineMelo, welcome to the community!

I notice you’re using render_template which is not defined. You need to update line 1 to import it:

from flask import Flask, render_template

Second, you don’t have a templates folder in your Repl. Add the templates folder and move the index.html file inside of it.

Third, your index.html file has this line in the head:

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}">

However, styles.css is not in the static folder. Change that line to this:

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">

So your HTML file references the correct CSS file.

Fourth (this is the reason the webview is not showing up), you run the Flask app twice. Instead, you should replace lines 17-20 of main.py with this:

if __name__ == '__main__':
    app.run(host='', port=82)

Thank you so much! All your tips worked!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.