Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'Markup' from 'flask' #25

Open
glopglopoups opened this issue Oct 12, 2023 · 4 comments
Open

ImportError: cannot import name 'Markup' from 'flask' #25

glopglopoups opened this issue Oct 12, 2023 · 4 comments

Comments

@glopglopoups
Copy link

Hello,

Following the evolution of Flask, an error appears on the "flask-markdown" module.

Would it be possible to fix the module to fit Flask 3.x. x?

Thank you for your help,

@dcolish
Copy link
Owner

dcolish commented Oct 28, 2023

If you can propose a fix I'm happy to review and approve. I stepped away from this project a long time ago after it was rejected for listing with approved flask plug-ins and left the code for the community.

If it's valuable I'd love to transfer ownership. I'll share an announcement in the readme and in an issue that it will be archived by end of year if no one has time to take it.

Thanks
Dan

TomGoBravo added a commit to TomGoBravo/tourist-with-flask that referenced this issue Nov 28, 2023
…upgrade-package werkzeug --upgrade-package flask-login --upgrade-package flask-wtf && pip-sync && python -m pytest

tests pass but there are new warnings:

flaskext/markdown.py:32: DeprecationWarning: 'flask.Markup' is deprecated
dcolish/flask-markdown#25

flask/testing.py:118: DeprecationWarning: The '__version__' attribute is deprecated
(can't find a fix)
TomGoBravo added a commit to TomGoBravo/tourist-with-flask that referenced this issue Nov 28, 2023
```
pip-compile -v --upgrade-package aiohttp --upgrade-package prefect --upgrade-package werkzeug --upgrade-package flask-login --upgrade-package flask-wtf && pip-sync && python -m pytest
```
    
Tests pass but there are new warnings:
    
`flaskext/markdown.py:32: DeprecationWarning: 'flask.Markup' is deprecated`
    dcolish/flask-markdown#25
    
`flask/testing.py:118: DeprecationWarning: The '__version__' attribute is deprecated`
    (can't find a fix)
@SSAdvisor
Copy link

SSAdvisor commented Dec 8, 2023

How about something like:

try:
    from flask import Markup
except:
    try:
         from markupsafe import Markup
    except:
         raise Exception('Markup module not found')

@SSAdvisor
Copy link

Here is what worked for me:

diff --git a/flaskext/markdown.py b/flaskext/markdown.py
index 0059852..413c2fd 100644
--- a/flaskext/markdown.py
+++ b/flaskext/markdown.py
@@ -29,8 +29,15 @@ decorating the extension class with :func:`extend`
 :license: BSD, MIT see LICENSE for more details.
 """
 from __future__ import absolute_import
-from flask import Markup
-from jinja2 import evalcontextfilter, escape
+try:
+    from flask import Markup
+except:
+    from markupsafe import Markup
+try:
+    from jinja2 import evalcontextfilter, escape
+except:
+    from jinja2 import pass_eval_context as evalcontextfilter
+    from markupsafe import escape
 import markdown as md
 from markdown import (
     blockprocessors,

vanzhiganov added a commit to vanzhiganov/flask-markdown that referenced this issue Dec 31, 2023
vanzhiganov added a commit to vanzhiganov/flask-markdown that referenced this issue Dec 31, 2023
@vanzhiganov
Copy link

vanzhiganov commented Dec 31, 2023

@dcolish
PR #26 based on diff from @SSAdvisor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants