python - Django 1.6 class-based views: How to get the right path/to/view/ in url template tags -


i have 2 listview -based views inside app called ‘events’. 1 'events_index' lives @ /events/ , other 'past_events_index' lives @ /events/past/.

navigating directly both urls loads desired pages a-ok. problem trying {% url %} template tag link 'past_events_index'.

apps/events/urls.py:

from django.conf.urls import patterns, url  .views import eventdetailview, eventlistview, pasteventlistview  urlpatterns = patterns(     'apps.events.views',     url(r'^$', eventlistview.as_view(), name='events_index'),     url(r'^past/$', pasteventlistview.as_view(), name='past_events_index'),     url(r'^(?p<slug>[-\w]+)/$', eventdetailview.as_view(), name="events_show"),     )    

apps/events/templates/events/index.html:

<a href="{% url 'events:past_events_index' %}">past events</a> 

instead of pointing me /events/past/ above points me /past/, yields 404. , when user @ /events/.

what missing? there leading slash getting appended somewhere?

here views in interest of being complete:

apps/events/views.py:

from .models import event django.views.generic import listview pure_pagination.mixins import paginationmixin datetime import datetime  class eventlistview(listview):     date_today = datetime.now().date()      queryset = event.objects.published().filter(is_feature=false).\         exclude(start_date__lte=date_today, end_date__isnull=true).\         exclude(start_date__lte=date_today, end_date__lte=date_today).\         exclude(start_date__isnull=true, end_date__lte=date_today)      template_name = "events/index.html"      def get_context_data(self, **kwargs):         date_today = datetime.now().date()          context = super(eventlistview, self).get_context_data(**kwargs)          context['featured_event'] = event.objects.published().filter(is_feature=true). \             exclude(start_date__lte=date_today, end_date__isnull=true). \             exclude(start_date__lte=date_today, end_date__lte=date_today). \             exclude(start_date__isnull=true, end_date__lte=date_today)          past_events = event.objects.published().filter(is_feature=false).\             exclude(start_date__gte=date_today).\             exclude(start_date__isnull=true, end_date__gte=date_today)          context['past_events'] = past_events.count()          return context   class pasteventlistview(paginationmixin, listview):     date_today = datetime.now().date()      queryset = event.objects.published().filter(is_feature=false).\         exclude(start_date__gte=date_today).\         exclude(start_date__isnull=true, end_date__gte=date_today).\         reverse()      template_name = "events/index.html"     paginate_by = 10      def get_context_data(self, **kwargs):         context = super(pasteventlistview, self).get_context_data(**kwargs)          context['is_past'] = true          return context   class eventdetailview(statusdetailview):     model = event 

settings/urls.py:

from django.conf import settings django.conf.urls import include, patterns, url django.contrib import admin django.contrib.staticfiles.urls import staticfiles_urlpatterns django.contrib.sitemaps.views import sitemap django.views.generic.base import redirectview  cms.sitemaps import cmssitemap  apps.news.sitemaps import newssitemap   admin.autodiscover()  sitemaps = {     'news': newssitemap,     'cmspages': cmssitemap, }   urlpatterns = patterns(     '',      url(r'^sitemap\.xml', sitemap, {'sitemaps': sitemaps}),      url(r'^garment/', include('apps.garment.urls')),      # django admin     (r"^%s/" % settings.admin_namespace, include(admin.site.urls)),      url(r"^", include('cms.urls')),      # urls apps     url(r'^', include('apps.news.urls')),     url(r'^events/', include('apps.events.urls', namespace='events', app_name='events')), )  if getattr(settings, "local_serve", false):     urlpatterns = patterns(         'django.views.static',         url(             r"^%s(?p<path>.*)$" % settings.media_url.lstrip('/'),             "serve",             {                    'document_root': settings.media_root,                 'show_indexes': true,             }),     ) + staticfiles_urlpatterns() + urlpatterns 

this solved namespacing. (and removing custom url prefix field on model overriding namespace.) credit @c.b.

namespace event urls within main urls.py, use 'events:past_events_index'


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -