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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:06:13+00:00 2026-06-05T09:06:13+00:00

I couldn’t place my question into one sentence. I was following a tutorial to

  • 0

I couldn’t place my question into one sentence.
I was following a tutorial to make a blog from scratch. But the tutorial predicted having all the categories, tags, months and years listings in separate templates.

I want to add a list of categories, a list of months and years on the main blog page.

So here is what I got. With this code, the list of categories is shown in the main page but only if you go to the blog/category url, and not in just blog/ where I want it to be.

    **(r'^$', list),**
    (r'^archive/(\d{1,2})/$', list),
    (r'^\d{2}/d{4}/$', month),
    (r'^([0-9]{4}/\d{1,2})/(?P<slug>.*)/$', detail),
    (r'^(?P<year>\d{4})/$', year),
    **(r'^category/$', category),**

I also tried:

    (r'^$', category),

but no luck.

This is the same code from the template in category.html and in list.html:

 {% if categories %}
        {% for category in categories %}
        <li class="cat-item"><a href="category/{{ category.name.lower }}/"
            title="{{ category.name.capitalize }}">
             {{ category.name.capitalize }}</a>
         </li>
         {% endfor %}
         {% endif %}

Views.py:

def category(request):
    return render_to_response('blog/list.html', {'categories':Category.objects.all(),},)

It was like this. I tried this, but no luck in def list:

return render_to_response('blog/list.html',{'posts':posts,
                                       'next':next,
                                       'previous':previous,
                                       'categories':Category.objects.all(),
                                       },)

How can I get what shows on blog/category to show on blog/ also?
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-05T09:06:14+00:00Added an answer on June 5, 2026 at 9:06 am

    When you type an url in your browser a request is sent to your server. Django then takes the url and matches it against it url patterns to determine the proper view. As soon as a view is found django stops matching and executes this view which in turn returns a response.

    If you want to use your categories in different views you either have to to make sure that in every view the same categories context variable is provided to the template or, which is usually much better, write a simple custom template tag. For your categories this could look like this:

    @register.inclusion_tag('blog/category_list.html')
    def categories_list():
        return { 'categories': Category.objects.all() }
    

    In the file ‘blog/categoy_list.html’ would then be the code that is currently both in ‘categories.html’ and ‘list.html’. In these files replace it with.

    {% load your_blog_tags %}
    {% categories_list %}
    

    You can use that then wherever you need a category list. Of course the same applies for years and month lists.

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

Sidebar

Related Questions

Couldn't think of a more appropriate question title, but I'm looking for some advice
i couldn't find in one place ,all the Appstore rules for the required images
Couldn't find an answer to this question. It must be obvious, but still. I
I couldn't really come up with a proper title for my question but allow
couldn't they make it simple, all you need is just uid and passwd, but
Couldn't find one but can't believe they don't have one.
Couldn't think of better phrasing for this question, but basically I want to store
Couldn't find better title but i need a Regex to extract link from sample
I couldn't find a straight answer to my question and need to know it
I couldn't find a more descriptive title, but here there is an example: import

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.