noob seeks help - int list into html links in template

hi, i have a filter that spits out a list like this: [9617229107649681212, 7009153596038865357, 18339269626061634110]

in the template i need each of those numbers in the list to be an html link, like this:

[<a href=/at/9617229107649681212>9617229107649681212</a>,  <a href=/at/7009153596038865357>7009153596038865357</a>,  <a href=/at/18339269626061634110>18339269626061634110</a>]

im sure this is super easy, I don’t know why i cant figure it out lol… here is the template section i currently have:

            <tr class="collapse show_more_info">
              <th>Contracts</th>
              <td class="text-monospace" style="word-wrap: break-word; max-width: 250px">{{ blk.ats|blkatid }}</td>
             </tr>

Which outputs this:
Contracts [9617229107649681212, 7009153596038865357, 18339269626061634110]

I was able to append the link info within the filter, but that just renders text <a href… rather than rendered html links. again django and python noob… be gentle :blush:

The output of a database query is a Queryset. You can iterate over the elements of a queryset in your template.

If you want more detailed or specific assistance, please post the view here so we can address your question in the context of the actual code.

again im really really new… I so want to do this in javascript and call it a day :smiley: but want to learn here… this is my filter… if this helps…

@register.filter
def blkatid(value: bytes) -> str:
    if not value:
        return ""
    lst=[]
    s = value.hex().upper()
    for x in (s[k:k+16] for k in range(0, len(s), 3*16)):
        i = struct.unpack('<Q', bytes.fromhex(x))[0]
#        j = str(i)
#        u = ("<a href=/at/" + j + ">" + j + "</a>")
        lst.append(i)
    return lst

ignore the test i was doing at the filter level, i commented that out, but it rendered the correct “text” just not useable links.

here is the view section that handles that data, not sure if it will help…

class AtDetailView(IntSlugDetailView):
    model = At
    queryset = At.objects.using("java_wallet").filter(latest=True).all()
    template_name = "ats/detail.html"
    context_object_name = "at"
    slug_field = "id"
    slug_url_kwarg = "id"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        obj = context[self.context_object_name]
        fill_at_data(obj)

        return context

There’s no need for the filter blkatid - that filter is all unnecessary work and making things much more difficult than they need to be.

For iterating over a queryset, refresh your memory with what you had done in the Django tutorial in step 3. In particular, review the section at Write views that actually do something.

Side note:

There is no reason to include the call to all in this query. It’s not doing anything for you in combination with the filter.

the filter is because the returned value is hex little endian that i need to modify to get my dec list in the first place… the hex value contains a bunch of other data not needed here. so i only need the first 16 characters out of each set of 48 which the filter is doing… but now that i have the listed accounts from the hex value im just trying to turn them into individual links. The call to all is gathering a bunch of other info… as shown here: i’m only conserned right now with making the “Contracts” section individual links to their contracts.

EDIT: just removing the links i posted to get help…

But you’re doing all this work in the wrong place. You should be doing it in the view and not in the template.

You’re making this so much harder on yourself this way.

yes i know there is a lot wrong with this project lol we had to bring it back to life in short order recently and will start going through and cleaning it up soon.

did you give up on me :joy: Just looking for help with what i already have. I get its probably not the most effective way.

No, I won’t say I have given up on you, but I’m not going to spend any time making a bad situation worse, either.

ok… well its been running for almost a decade, with very low resource usage in production taking on many hits/min and a db with over 14 million rows in the database. that’s the fun of programming there are 10 ways to do something. sure my way may not be perfect, but it functions and im just looking to turn a list into link here… My OP was not looking for advise to rewrite the project. But i do appreciate you reaching out with the useful links you sent. and FYI im going to be going through cleaning up and fixing past issues as i learn…

Is there anyone else who can help with my simple request in post #1 that I need a hand on?

found my solution and it works great… thanks anyway guys…