School is a twelve-year jail sentence where bad habits are the only curriculum truly learned.
John Taylor Gatto
New forum topics
Recent comments
- you have to use source
3 days 18 hours ago - Why not just use this method
4 days 9 hours ago - Great!!!
1 week 4 hours ago - Really working with internet
1 week 11 hours ago - I haven't explored Puppet
5 weeks 8 hours ago - Wouldn't puppet be more
5 weeks 22 hours ago - I agree with the previous
11 weeks 1 day ago - how did this go when you
12 weeks 1 day ago - First off let me say thank
14 weeks 16 hours ago - You are my hero. :) Worked
18 weeks 1 day ago
When coding Django one of my most important goals is avoiding all kind of hardcoded urls in my applications. Let's see this line from one of my app's URLConf:
url(r'^edit/object/(?P<object_id>\w+)/$', 'object_edit', name='object_edit'),
This points to a page like /edit/object/123, notice I'm using a named pattern here, and calls a view defined with:
def object_edit(request, object_id):
Then I can do what I need with the object identified by object_id.
Now, imagine I have a list of objects in a template so I can add an edit link to each one of them, something like this:
<a href="{% url object_edit object_id=4}">edit object</a>
Notice that 4? I put it there just for making my point clear, what I really want to do is something like:
<a href="{% url object_edit object_id={{ object.object_id }} %}">edit object</a>
but that produces an error like this: TemplateSyntaxError at ... Could not parse the remainder: '{{' from '{{'.
It seems a template variable can't be used inside a {% url %} tag, and I guess the same applies to any template tag. After thinking a bit about how other tags work with variables, the {% for %} loop for example, I decided to get rid of the {{ and }}:
<a href="{% url object_edit object_id=object.object_id %}">edit object</a>
And yep, that worked. I hope this helps anybody else having a similar question.
Related content
- Django questions and answers with a Swedish guy
- How to use a public IP address with Google App Engine development server
- How to setup Apache, mod_python and a reverse proxy to Lighttpd for Django on Ubuntu
- PYTHONPATH and configuring Django with Apache and mod_python
- HTTP 200 testing Django applications with Facebook
Also visit
Other Resources
- Cloud based Task Management Software
- Top rated project scheduling software
- Daniel E Straus Aveta

Join the conversation
Thanks, solved my problem
Thanks, solved my problem
Thanks. I needed that!
Thanks. I needed that!
Thank You! Was stuck for a
Thank You! Was stuck for a while on this.