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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:17:12+00:00 2026-06-14T15:17:12+00:00

I’m trying to get to grips with class based views. I have urls.py as

  • 0

I’m trying to get to grips with class based views.

I have urls.py as follows:

urlpatterns = patterns('homework.views',

(r'^index/$', 'index'),
url(r'^(?P<sub_slug>\w+)/$', NavListView.as_view(), name='nav'),
url(r'^(?P<sub_slug>\w+)/(?P<class_grp_slug>\w+)/$', SubNavListView.as_view(), name='subnav'),

url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),)

I have my views.py:

# Subject navigation
class NavListView(ListView):
    template_name = 'templates/home.html'

    def get_queryset(self):
        self.subject = Subject.objects.all()
        return self.subject

    def get_context_data(self, **kwargs):
        context = super(NavListView, self).get_context_data(**kwargs)
        context['subjects'] = self.subject
        return context

# Class group navigation
class SubNavListView(NavListView):

    def get_queryset(self):
        self.group = Group.objects.filter(subject__name__iexact=self.kwargs['sub_slug'])
        return self.group

    def get_context_data(self, **kwargs):
        context = super(NavListView, self).get_context_data(**kwargs)
        context['groups'] = self.group
        return context

In my ‘templates/home.html’ I have:

{% extends 'templates/base.html' %}
{% load url from future %}

{% block nav-menu-items %}
<ul class="nav">
    {% for sub in subjects %}
    <li class=""><a href="{% url 'nav' sub_slug %}">{{ sub }}</a></li>
    {% endfor %}
    <li class="active"><a href="#">Add Subject</a></li>
</ul>
{% endblock nav-menu-items %}

{% block class_groups_nav %}
<div class="tabbable">
  <ul class="nav nav-tabs">
    {% for group in groups %}
    <li>
      <a data-toggle="tab" href="{% url 'subnav' sub_slug class_grp_slug %}">{{ group }}</a>
    </li>
    {% endfor %}
    <li><a href="#">Add</a></li>
  </ul>
{% endblock class_groups_nav %}

I’m trying to achieve a ‘nav’ of subjects, then a ‘subnav’ below showing a tab for each class group for the subject selected in the navigation above.

I’ve tried different ways of doing this such as making Subject.objects.all() available as context processors. I have also attempted to subclass NavListView so I can inherit the previous context, making them available in SubNavListView.

At the moment, I’m getting a NoReverseMatch error where the url named ‘nav’ is not passing the sub_slug and so I can’t use it in the url in the template.

Any thoughts on getting this working?

Many thanks,

  • 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-14T15:17:13+00:00Added an answer on June 14, 2026 at 3:17 pm

    Assuming your Subject model has field named slug in it, you need to update your code to

    <li class=""><a href="{% url 'nav' sub.slug %}">{{ sub }}</a></li>
    

    ie. pass an appropriate parameter to {%url ... %}. Change sub.slug to whatever field name you want to refer to.

    If you want to, you can also do {% url 'nav' sub_slug=sub.slug %}.

    You are trying to pass sub_slug, but which is not defined in the template context, and result in empty string. So nav url will not get any parameter.

    I see similar problem in your other {%url ...%} tags in the template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.