djangogoogle-app-engineurlhrefurlconf

Django on App Engine URLs


I'm have a problem with my urls using Django on App Engine.

HTML:

<li>Welcome {{ user.first_name }}</li>
<li><a href="logout/">Logout</a></li>

urls.py

    from django.conf.urls import patterns, include, url
from django.contrib import admin
from home import views
from registration import views

admin.autodiscover()

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'home.views.index', name='home'),
    url(r'^login/$', 'registration.views.login_view', name='login'),
    url(r'^register/$', 'registration.views.coach_register', name='coach_register'),
    url(r'^activate/$', 'registration.views.activate', name='activate'),
    url(r'^logout/$','registration.views.logout_view', name='logout'),

]

What's happening is that if I click logout from any page other than the home page (ie. 'register'), then it will search for a url 'register/logout/' which doesn't exist as the url for the logout view is just 'logout/'

I tried changing the urlconf to set the logout url to

url(r'^register/logout/$' ...)

But this also fails when trying to use the button if on other pages that don't include just 'register/' in the url.

Not sure how to solve this problem, but it seems to me like it should be simple. What am I clueless about as to handle these?


Solution

  • The behaviour shown by App Engine / Django is to be expected. You have used relative urls in your template. Thus when you are viewing the webpage at /register/ the above link would point to '/register/logout/' similarly if you were /activate/ page the link would be '/activate/logout/'

    The solution? use absolute url eg '/logout/'