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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:22:35+00:00 2026-05-24T02:22:35+00:00

In django, which should I generally prefer, and why? long template variable names, passing

  • 0

In django, which should I generally prefer, and why?

  • long template variable names, passing as few “root objects” (e.g. request) as possible:

    {% if request.current_page.get_children.0.get_absolute_url %}

  • or pass a hell lot of different “root objects” and keep the template variable name simple:

    {% if first_child_url %}

  • somewhere in the middle, e.g. passing children

    {% if children.0.get_absolute_url %}

    or passing first_child

    {% if first_child.get_absolute_url %}

the advantage of the first approach is looser coupling, since I won’t need to change the view every time I need to use another variable; the advantage of the second approach is that the template is simpler and much cleaner.

If I’m using generic views (or third party views) which does not allow me to add additional context variables (therefore the only way to add context variables is by writing middleware or context processors), would that change anything?

  • 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-24T02:22:36+00:00Added an answer on May 24, 2026 at 2:22 am

    There is no right answer for this, but I can give you something else to consider:

    1) Mistyped variable names in a template will fail silently, which is why I normally try to avoid things like

    {% if request.current_page.get_children.0.get_absolute_url %}
    

    2) In contrast to that, any issues in a view will immediately raise exceptions and be obvious to debug

    first_child_url = request.current_page.get_children[0].get_absolute_url
    

    3) What I sometimes do when the situation calls for it, is add shortcut methods to a model which allows me to call the method from the template but still keeping the complexity on the python side of the equation.

    All that said, if you can’t add extra context and need to do it using template tags (as mentioned in your comments) I think its best if you go for the complicated template option.
    I only use custom template tags when it is the only way to do something, never as a shortcut.

    Hope this helps….

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

Sidebar

Related Questions

I am currently using Django to construct JSON encoded objects which a retrieved using
I'm using django-registration which somehow stopped working the way it should work. I'm completely
Are there any important features in Rails or Django which do not exist in
Django view points to a function, which can be a problem if you want
Django comes with CSRF protection middleware , which generates a unique per-session token for
My Django app has a Person table, which contains the following text in a
i've got some weird characters in my database, which seem to mess up django
In Django's template language, you can use {% url [viewname] [args] %} to generate
Does Django have any template tags to generate common HTML markup? For example, I
We are looking for an approach for developing a web based application which should

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.