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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:17:52+00:00 2026-05-28T01:17:52+00:00

Intention In my Django template, I create a link for each letter in the

  • 0

Intention

In my Django template, I create a link for each letter in the alphabet and each digit 1-9 to link to an index page.

In Python code, this is what it would look like:

for ch in map(chr, range(97, 123)) + range(1,10):
    print '<a href="/indexpage/{0}/">{0}</a>'.format(ch)

But I want to do this in a Django template, so I can’t use the map/range functions directly.

Failed Attempts

At first, I thought about creating a template tag that returns the alphanumeric character list, and then looping over it in the template, but this does not work, as it’s a tag and not a context variable.

Templatetag:

@register.simple_tag
def alnumrange():
    return map(chr, range(97, 123)) + range(1,10)

Template:

{% for ch in alnumrange %}
    <a href="/indexpage/{{ch}}/">{{ch}}</a>
{% endfor %}

I thought it might work when using the with tag, but it didn’t either.

Further thoughts

  • I can’t set the context in a view as this is a base template which I extend.
  • I don’t want to add a context processor, as I use this range only in a single template.

Is there a way to turn the template tag output into a context variable over which I can iterate? Or is there another way I should solve this?

  • 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-05-28T01:17:53+00:00Added an answer on May 28, 2026 at 1:17 am

    You need inclusion tag here. Just pass your range in context and render it as you like. It gives you flexible and modular structure.

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

Sidebar

Related Questions

Consider this bit of obfuscated code. The intention is to create a new object
This is the code section from inno setup.My intention is to make two Checkbox
I am getting an Indention Error. This code is straight from the django first
My intention is to create a menu at the top of the page which
The intention of following (simplified) code fragment is to return one random row .
I have the following code with the intention of locating values from within a
I am quite new to django, and I have built a small page using
I have to insert 8000+ records into a SQLite database using Django's ORM. This
My intention in this question is not to be pedantic, but rather to explore
My intention was to use pyGTK's main loop to create a function that blocks

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.