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 8675403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:56:28+00:00 2026-06-12T19:56:28+00:00

I have an error when trying to use the url_for method in Flask. I’m

  • 0

I have an error when trying to use the url_for method in Flask. I’m not sure what the cause of it because I only follow the Flask quick start. I’m a Java guy with a bit of Python experience and want to learn Flask.

Here’s the trace:

Traceback (most recent call last):
  File "hello.py", line 36, in <module>
    print url_for(login)
  File "/home/cobi/Dev/env/flask/latest/flask/helpers.py", line 259, in url_for
    if endpoint[:1] == '.':
TypeError: 'function' object has no attribute '__getitem__

My code is like this:

from flask import Flask, url_for
app = Flask(__name__)
app.debug = True

@app.route('/login/<username>')
def login(): pass

with app.test_request_context():
  print url_for(login)

I’m have tried both the stable and development version of Flask and the error still occurs. Any help will be much appreciated! Thank you and sorry if my English is not very good.

  • 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-12T19:56:29+00:00Added an answer on June 12, 2026 at 7:56 pm

    The docs say that url_for takes a string, not a function. You also need to provide a username since the route you created requires one.

    Do this instead:

    with app.test_request_context():
        print url_for('login', username='testuser')
    

    You are receiving this error because strings have a __getitem__ method but functions do not.

    >>> def myfunc():
    ...     pass
    ... 
    >>> myfunc.__getitem__
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'function' object has no attribute '__getitem__'
    >>> 'myfunc'.__getitem__
    <method-wrapper '__getitem__' of str object at 0x10049fde0>
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have an error message when the use enters a number
I have the following error Exception in thread main javax.naming.NameNotFoundException: CounterBean not bound trying
I'm currently trying to use a custom method in Rails and I do not
I have this error when trying to generate the meta model with JOOQ: org.jooq.exception.DataAccessException:
I have encountered this error when trying to delete a cell, using a custom
I have this error when I am trying to read the file: Exception in
I have an error in MVC/Controllers/ProductCOntroller.cs when trying to build solution. Need to have
This time I have an error which I have been trying again to figure
I get this error when trying to link a win32 exe project. I have
I'm trying to launch my client, but have an error. Server is already running

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.