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

  • SEARCH
  • Home
  • 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 8226045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:37:37+00:00 2026-06-07T15:37:37+00:00

Here is my example: from flask import Flask app = Flask(__name__) def add1(f): def

  • 0

Here is my example:

from flask import Flask

app = Flask(__name__)
def add1(f):
    def inner(*args, **kwargs):
        return str(f(*args, **kwargs))+'1'
    return inner


@app.route('/')
@add1
def hello1():
    return "hello1";

@app.route('/hello2')
@add1
def hello2():
    return "hello2";


if(__name__ =='__main__'):
    app.run()

When I run 127.0.0.1:5000, I expect to get “hello11”, but I get “hello21”, why?

  • 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-07T15:37:39+00:00Added an answer on June 7, 2026 at 3:37 pm

    The problem is that Flask keeps track of the functions by name, and because the functions getting passed to app.route(path) are both called inner, the second one (hello2) overwrites the first. To fix this, you will need the name of the inner function to be changed to the name of the function it is decorating. You can change the decorator to

    def add1(f):
        def inner(*args, **kwargs):
            return str(f(*args, **kwargs))+'1'
        inner.__name__ = f.__name__
        return inner
    

    which will work, but is not as elegant as the standard library solution,

    from functools import wraps
    
    def add1(f):
        @wraps(f)
        def inner(*args, **kwargs):
            return str(f(*args, **kwargs))+'1'
        return inner
    

    The wraps decorator not only fixes the name, but the docstring, the file, and the attribute dictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I follow example from here using section listview http://lalit3686.blogspot.com/2012/05/sectionadapter.html But how can I implement
i am trying one example from Here for ontouch image zoom and touch on
I currently have a csv file that I'm parsing with an example from here:
I try to read out all existing calendars. I tried the example from here:
Here's an example taken from http://docs.jquery.com/API/1.1/AJAX#.24.post.28_url.2C_params.2C_callback_.29 $.ajax({ type: POST, url: some.php, data: name=John&location=Boston, success:
So the example from the wiki has phantom.exit() in two places here. Why can't
I'm using the SSLStream example from msdn here . The client code seems to
I am working through the example from https://blogs.oracle.com/arungupta/entry/java_ee_6_and_nosql . Here is a link to
I have a simple java project (adapted from the example here ), which is
Going from the example given here... http://ericswann.org/blog/archive/2009/04/06/linq-to-sql-datacontext-provider-revisited.aspx I'm trying to use the datacontext between

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.