Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:18:34+00:00 2026-06-09T17:18:34+00:00

I find it quite confusing what exactly are the differences in using Flask’s before_request()

  • 0

I find it quite confusing what exactly are the differences in using Flask’s before_request() and/or after_request() versus using a WSGI middleware.

Say I want to do something very silly like this:

  • Every request-body should be scanned for the word “bacon” and be replaced with “eggs”.
  • Now request hits flask-view (according to url-mapping), view-function creates the response
  • Every response-body should be scanned for “eggs” and replaced with “bacon”

Would I use a WSGI middleware or the Flask functions? Coming from django with a very robust middleware suite, the difference is not clear to me.

Thanks in advance.
berni

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:18:35+00:00Added an answer on June 9, 2026 at 5:18 pm

    Actually, you have the exact same choice in Django. Django, in some part, is built on WSGI, so you could theoretically write WSGI middleware or Django middleware in Django as well. The reason you don’t have confusion there is because the Django community typically steers developers away from WSGI middleware. One reason is due to the fact that Django was designed to work equally on mod_python and WSGI. By using the Django middleware, your middleware works on both systems (see this post by James Bennett).

    One advantage that creating a WSGI middleware has is that it can be used in multiple frameworks. For example, Beaker is a session and caching WSGI middleware that could be used in any WSGI framework. If it were written specifically in Flask, then Pyramid developers couldn’t use it. The maintainer of the library specifically made sure that the library could work in multiple frameworks, so he wrote it as a WSGI library.

    Basically, this is how I would make my decision:

    1. If you are just writing a middleware that does something specific to your application, use the middleware of your framework.
    2. If you think your middleware is useful in a few of your apps, and might be helpful for other people, still use the middleware of your framework (what Flask would really typically call an “extension”). See Flask-SQLAlchemy as an example.
    3. If people are becoming really interested in your middleware, and are willing to help, think about converting it to an WSGI middleware library so that it can be used in other frameworks.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I find myself using the current pattern quite often in my code nowadays var
I find myself using hash arguments to constructors quite a bit, especially when writing
Using proguard seems to be quite confusing. I am interested in simply obfuscating a
I am new to JS and find the whole paradigm quite confusing. In trying
I have searched the net and searched the net only to not quite find
This seems like it should be easy, but I can't quite find an explanation
I am learning Computer Networking this semester, on which I find it quite interesting
first post here, I come in peace :) I've searched but can't quite find
Had a good read through similar topics but I can't quite a) find one
Aside from the PEAR repository, which I find often has quite messy code with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.