Learn to Code via Tutorials on Repl.it!

← Back to all posts
Flask/Replit.web import errors and how to fix them.

Error when importing Flask and replit DB

Seeing this when importing both Flask and replit DB?

That's because the replit package includes it's own Flask fork that conflicts with Flask. Instead of using from flask import Flask use from replit.web import App and use app = App(__name__) instead of app = Flask(__name__). This flask fork adds a few new features like login with replit for your site. See its docs here https://replit-py.readthedocs.io/en/latest/index.html

Error when trying to import Response from replit.web

You might've run into this when trying to do things like specifying MIME types in your template renders. In Flask, you could fix them like this:
Response("Response CSS", mimetype="text/css")

However that doesn't work in replit.web. There is a workaround, however:
1. Add flask = "^1.1.2" to pyproject.toml under [tool.poetry.dependencies]
2. Use from flask import Response in your code.

Error attempting to use replit.web on a thread other than the main thread

You cannot multithread replit.web, so we must use a version of Flask that is compatible with the replit module.
1. Add flask = "^1.1.2" to pyproject.toml under [tool.poetry.dependencies]
2. Use from flask import Flask in your code instead of from replit.web import App, app = Flask(__name__) instead of app = App(__name__) and app.run("") instead of app.run(). You should now be able to thread Flask and use it along with Replit DB!