Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Forked from angelabauer/main.py
Last active September 25, 2026 06:03
Show Gist options
  • Select an option

  • Save TheMuellenator/29acd670326c6313bc2b8f7e66fd441f to your computer and use it in GitHub Desktop.

Select an option

Save TheMuellenator/29acd670326c6313bc2b8f7e66fd441f to your computer and use it in GitHub Desktop.
Day 61 L464 - Installing Flask-WTF
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def home():
return render_template('index.html')
@app.route("/login")
def login():
return render_template("login.html")
if __name__ == '__main__':
app.run(debug=True)
@EugeneYe1

Copy link
Copy Markdown

Flask==2.2.2
itsdangerous==2.1.2
flask

Copy and paste that into the requirements.txt and you should be prompted to install the plugin in the main.py python file.

@idan6767

idan6767 commented Feb 3, 2023

Copy link
Copy Markdown

so there is a problem with how the login button behave.
aperrantly "button" tags dont accept href, to fix this all you neeed to do is to seperate them, like that:

	<a href="{{ url_for('login') }}">
            <button class="btn btn-primary btn-lg">Login</button>
            </a>

@abeyasmare

abeyasmare commented Feb 26, 2023 •

Copy link
Copy Markdown

For all your problems for this projects

  1. for jinja and flask related problems simply do pip uninstall jinja2 flask after that do pip install jinja2 flask that will work just fine but if it dont make sure the requirements file has the latest dependencies
  2. for the button not working, button tag doesnot have href attribute, it may work if you add onclick listener (it is javaScript code) but buttons are interactive and it is activated when user interacts with them. so when they are activated it performs an action. the actions can be js code (event listeners) or it can be activated using form tag that has action attribute and specifing the type of requests using method

@cipa5

cipa5 commented Apr 10, 2023

Copy link
Copy Markdown

ImportError: cannot import name 'Markup' from 'jinja2' for me and I cant solve it..

You need to install Flask==2.2.3. To do this first 1) pip install --upgrade -pip, then 2) uninstall current flask and jinja using pip uninstall Flask Jinja2, 3) install them again using pip install Flask Jinja2, finally 4) utilize pip freeze to check the current state of environment packages. At this moment this looks like this to me but it might change in the future depending on the version of the specific package:
click==8.1.3
Flask==1.0.2
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
Werkzeug==2.2.3
Of course all this commands have to be executed in Terminal

@shyam3017

Copy link
Copy Markdown

why the login button is not working?

@shyam3017

Copy link
Copy Markdown

so there is a problem with how the login button behave. aperrantly "button" tags dont accept href, to fix this all you neeed to do is to seperate them, like that:

	<a href="{{ url_for('login') }}">
            <button class="btn btn-primary btn-lg">Login</button>
            </a>
`This works thank you

@arpy8

arpy8 commented May 7, 2023 •

Copy link
Copy Markdown

ImportError: cannot import name 'Markup' from 'jinja2' for me and I cant solve it..

Can any one help me, how to resolve this problem

https://stackoverflow.com/questions/71645272/importerror-cannot-import-name-markup-from-jinja2

this might help you

@parvathyhydro

Copy link
Copy Markdown

Hi there!

If anyone gets an error while starting the project, just make these changes to requirements.txt

Flask==2.0.3
Jinja2==3.1.1
itsdangerous==2.0.1
flask

@parvathyhydro

Copy link
Copy Markdown

Thank you so much it help me out .

@Wrinklytech

Copy link
Copy Markdown

so there is a problem with how the login button behave. aperrantly "button" tags dont accept href, to fix this all you neeed to do is to seperate them, like that:

	<a href="{{ url_for('login') }}">
            <button class="btn btn-primary btn-lg">Login</button>
            </a>
`This works thank you
<button onclick="window.location.href='{{ url_for('login') }}';">Login</button>

This also seems to work.

@bahae3

bahae3 commented Jun 11, 2023

Copy link
Copy Markdown

I received this: from jinja2 import Markup, escape ImportError: cannot import name 'Markup' from 'jinja2'

Tried the methods above but it did not work. What should I do?

Hi,
try this on your terminal: pip install --upgrade flask jinja2

@ba2slk

ba2slk commented Jun 15, 2023

Copy link
Copy Markdown

For everyone who suffers from ImportError:
type this code below in your Terminal.

pip install Flask==2.0.3

This worked for me. Good Luck!

@inavadeep1205

Copy link
Copy Markdown
app = Flask(__name__)

@app.route("/")
def login():
    return render_template("login.html")

app.run()

@stevenson007

Copy link
Copy Markdown

I still have this error message after upgrading the framworks.
Capture

@bastiandargent

Copy link
Copy Markdown

I still have this error message after upgrading the framworks. Capture

Add Werkzeug==2.2.2 to your requirements.txt

@Serdieque

Copy link
Copy Markdown

I still have error on "address already in use and start with a new server port"

@DevFaizan786

Copy link
Copy Markdown

For people who see this part in December 2022 and receive error : ImportError: cannot import name 'Markup' from 'jinja2', put below codes inside of requirement.txt. Good luck!.

click==8.0.4 Flask==2.0.3 itsdangerous==2.1.2 Jinja2==3.1.1 MarkupSafe==2.1.1 Werkzeug==2.0.3

Thanks man this works.

@Miguel-Barroso

Copy link
Copy Markdown

If you don't understand why there is no Login button, go back and check the lessons on Bootstrap!

@olatideenoch

Copy link
Copy Markdown

Just incase someone might need it. Here are the updated version of the required packages in the requirements.txt file

Bootstrap_Flask==2.5.0
Flask==3.1.2
WTForms==3.2.1
Flask_WTF==1.2.2
Werkzeug==3.1.3

@Prodigymax

Copy link
Copy Markdown

Just in case anyone might need this. These worked for me, perfectly well. Cheers
Bootstrap_Flask==2.5.0
Flask==3.1.2
WTForms==3.0.1
Flask_WTF==1.2.1
Werkzeug==3.1.0
Jinja2==3.1.2
itsdangerous==2.2.0
flask

@Andresbello-GUI

Copy link
Copy Markdown

Just in case anyone might need this. These worked for me, perfectly well. Cheers Bootstrap_Flask==2.5.0 Flask==3.1.2 WTForms==3.0.1 Flask_WTF==1.2.1 Werkzeug==3.1.0 Jinja2==3.1.2 itsdangerous==2.2.0 flask

Thank you

@awapreethi

Copy link
Copy Markdown

Python 3.14 this is the updated requirements.txt that worked for me.
Bootstrap_Flask==2.4.0
Flask==3.1.0
WTForms==3.0.1
Flask_WTF==1.2.2
Werkzeug==3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment