Question

Hi I'm working with a Google app engine project with Django 1.5 support and the problem goes like this:

I wrote a helper decorator to call my views with a google user as a parameter:

def login(required=True):
    def _wrapper(f):
        @wraps(f)
        def __wrapper(request, *args, **kwargs):
            user = users.get_current_user()
            if required and user:
                return f(request, user, *args, **kwargs)
            elif required and not user:
                url = users.create_login_url(request.get_full_path())
                return HttpResponsePermanentRedirect(url)
            elif user:
                return f(request, user, None, *args, **kwargs)
            else:
                url = users.create_login_url(request.get_full_path())
                return f(request, user, url, *args, **kwargs)
        return __wrapper
    return _wrapper

If the view requires the user to be logged in it checks the current google user, the view may not require it, it that case it just calls the view. Now I've got the new two views:

pages.urls.py

urlpatterns = patterns('projecct.pages.views',
    url(r'^help/$', 'hlp', name='pages-help'),
)

The views

@login(required=False)
def homepage(request, user, login_url):
    """
    Site wide home page
    """
    return render_to_response(
        'pages/home.html',
        {'user': user, 'login_url': login_url, })

@login(required=False)
def hlp(request, user, login_url):
    return render_to_response(
        'pages/help.html',
        {'user': user, 'login_url': login_url})

The error:

NoReverseMatch at /
Reverse for 'pages-help' with arguments '()' and keyword arguments '{}' not found.
Request Method: GET
Request URL:    http://localhost:8080/
Django Version: 1.5
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'pages-help' with arguments '()' and keyword arguments '{}' not found.

...

Reverse for 'pages-help' with arguments '()' and keyword arguments '{}' not found.


{% if user %}
  <a href="{% url 'userprofile-show' %}">...</a>
{% else %}
  <a href="{{ login_url }}">Login</a>
{% endif %}
*<a href="{% url 'pages-help' %}">...</a>* 

The line with the 'pages-help' url is the highlighted by Django, aditionaly it marks the last else of the decorator as the cause of the error:

else:
    url = users.create_login_url(request.get_full_path())
    return f(request, user, url, *args, **kwargs)

Assuming this is the cause of the error why it didn't failed when proccessed the homepage view since it uses the same decorator and the same parameter?

And the other named url 'userprofile-show' it also uses the same decorator and didn't fail when it processed the tamplate:

@login(required=True)
def show(request, current_user):
    ...

I'm out of ideas, any help will be appreciated.

Edit. Added the root urls.py

urlpatterns = patterns('',
    url(r'^profile/', include('project.userprofile.urls')),
    # Static pages
    url(r'^pages/$', include('project.pages.urls')),
    url(r'^$', 'project.pages.views.homepage', name='homepage'),
)
Was it helpful?

Solution

The problem was with this line in root urls:

url(r'^pages/$', include('project.pages.urls')),

I just removed the $ at the end of the regex, it wasn't catching the app's urls.py because of that $. Noob mistake.

Anyway thanks for the help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top