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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:11:22+00:00 2026-05-23T07:11:22+00:00

There’s a feature in Twitter called hashtags that extracts tags from messages. For example,

  • 0

There’s a feature in Twitter called hashtags that extracts tags from messages.
For example, in

"Hey #guys, I love #stackoverflow"

#guys and #stackoverflow are clickable and lead to their own queries.

I’m building a similar app for training, and I wonder where and when to actually inject links in the output?

I grab all recent tweets:

def index(request):
    latest_tweets = Tweet.objects.all().order_by('-pub_date')[:5]
    return render_to_response('index.html',
                              { 'tweets': latest_tweets },
                              context_instance=RequestContext(request)
                              )

And in a block I render:

{% for tweet in tweets %}
    <p>{{tweet.message}}</p>
{% endfor %}

But this of course only shows plain message, no links.
I want each #tag in message to be replaced with a link passing tag name in a query string to a view called by_tag.

Does inserting <a href="...">s belong to views.py? Then what if I later decided this to be an AJAX link? Okay, seems like this belongs to templates. But how do I do such a complex replacement with routing from a template? Should I write a custom template filter?

Just for the reference, a Tweet contains its Tags in a field called tags.

  • 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-23T07:11:22+00:00Added an answer on May 23, 2026 at 7:11 am

    I did something similar last week and wrote a quick custom template filter to scan text looking for mentions and hashtags and wrap them in links.

    https://gist.github.com/1023144

    It makes sense to do this at the template level as you are performing HTML markup/replacement.

    Generally, your views perform routing logic, i.e. taking the url, retrieving and aggregating the necessary data, and rendering the template.

    If there is any associated logic you need to perform on a model (i.e. compare to tweets for example), it is a good idea to put this in Model functions, or Model Managers, as it is logic tied to you Models and Database.

    Any logic in at the template level should generally address the structuring and displaying the data it has received from the view.

    Sometimes though, you might want to perform some logic at the template level so that it can be reused across different views (like grabbing the top 10 most popular tags for example). This is a good time to create a template tag to perform the logic (and it’s also nice and reuseable)

    Anyway, place that code in:

    yourapp/templatetags.py
    

    and in the template:

    {% for tweet in tweets %}
        <p>{{ tweet.message|twittify }}</p>
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a website called Gild.com that has different coding puzzles/challenges for users to
There are many tutorials that talk about deleting index.php from the url. But I
There is a conversion process that is needed when migrating Visual Studio 2005 web
There is a field in my company's Contacts table. In that table, there is
There is no doubt that MonoTouch is one of the great cross-compiler(s). Similarly, SenchaTouch
There is a class that's a fully fledged UIViewController and when that page loads
There is a security concept regarding the calls to the WCF service that I
There is a statement in the foudations of Qt Development book that goes as
There is a constant I'm using from the iOS SDK. I printed out the
There is a process that seems to be running all the time in SQL

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.