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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:45:45+00:00 2026-05-10T15:45:45+00:00

I’ve got a brand new Django project. I’ve added one minimal view function to

  • 0

I’ve got a brand new Django project. I’ve added one minimal view function to views.py, and one URL pattern to urls.py, passing the view by function reference instead of a string:

# urls.py # -------  # coding=utf-8  from django.conf.urls.defaults import *  from myapp import views   urlpatterns = patterns('',     url(r'^myview/$', views.myview), )   # views.py ----------  # coding=utf-8  from django.http import HttpResponse   def myview(request):     return HttpResponse('MYVIEW LOL',  content_type='text/plain') 

I’m trying to use reverse() to get the URL, by passing it a function reference. But I’m not getting a match, despite confirming that the view function I’m passing to reverse is the exact same view function I put in the URL pattern:

>>> from django.core.urlresolvers import reverse >>> import urls >>> from myapp import views  >>> urls.urlpatterns[0].callback is views.myview True  >>> reverse(views.myview) Traceback (most recent call last):   File '<console>', line 1, in <module>   File '/Library/Python/2.5/site-packages/django/core/urlresolvers.py', line 254, in reverse     *args, **kwargs)))   File '/Library/Python/2.5/site-packages/django/core/urlresolvers.py', line 243, in reverse     'arguments '%s' not found.' % (lookup_view, args, kwargs)) NoReverseMatch: Reverse for '<function myview at 0x6fe6b0>' with arguments '()' and keyword arguments '{}' not found. 

As far as I can tell from the documentation, function references should be fine in both the URL pattern and reverse().

  • URL patterns with function references
  • reverse with function references

I’m using the Django trunk, revision 9092.

  • 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. 2026-05-10T15:45:46+00:00Added an answer on May 10, 2026 at 3:45 pm

    Got it!! The problem is that some of the imports are of myproject.myapp.views, and some are just of myapp.views. This is confusing the Python module system enough that it no longer detects the functions as the same object. This is because your main settings.py probably has a line like:

    ROOT_URLCONF = `myproject.urls` 

    To solve this, try using the full import in your shell session:

    >>> from django.core.urlresolvers import reverse >>> from myproject.myapp import views >>> reverse(views.myview) '/myview/' 

    Here’s a log of the debugging session, for any interested future readers:

    >>> from django.core import urlresolvers >>> from myapp import myview >>> urlresolvers.get_resolver (None).reverse_dict {None: ([(u'myview/', [])], 'myview/$'), <function myview at 0x845d17c>: ([(u'myview/', [])], 'myview/$')} >>> v1 = urlresolvers.get_resolver (None).reverse_dict.items ()[1][0] >>> reverse(v1) '/myview/' >>> v1 is myview False >>> v1.__module__ 'testproject.myapp.views' >>> myview.__module__ 'myapp.views' 

    What happens if you change the URL match to be r'^myview/$'?


    Have you tried it with the view name? Something like reverse ('myapp.myview')?

    Is urls.py the root URLconf, or in the myapp application? There needs to be a full path from the root to a view for it to be resolved. If that’s myproject/myapp/urls.py, then in myproject/urls.py you’ll need code like this:

    from django.conf.urls.defaults import patterns urlpatterns = patterns ('',     (r'^/', 'myapp.urls'), ) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I have a partly working solution now. I followed Ian's… May 11, 2026 at 11:37 pm
  • Editorial Team
    Editorial Team added an answer I found a solution to my problem, although it doesn't… May 11, 2026 at 11:37 pm
  • Editorial Team
    Editorial Team added an answer You need a range query, as described in SolrQuerySyntax. Basically,… May 11, 2026 at 11:37 pm

Related Questions

I've got a Windows Forms application with two ListBox controls on the same form.
I've got a simple CakePHP site (1.2) . I've got a page where you
A problem I ran into a while back I never found a good solution
For ASP.Net application deployment what type of information (if any) are you storing in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.