django-templates

How much flexibility is there in a Django for loop?

I am outputting a series of Django objects in a template: {% for obj in list %} ... {% endfor %} But I'd like to only output the first five of these, then put the remainder in the seperate <DIV>. The idea being, that I can hide the second half until required. I envisage something like this, but need to restrict the elements itera...

view on site

Why view on site linked to an unwanted page.Can i disable view on site ...

How do I translate a ISO 8601 datetime string into a Python datetime object?

I'm getting a datetime string in a format like "2009-05-28T16:15:00" (this is ISO 8601, I believe) one hack-ish option seems to be to parse the string using time.strptime and passing the first 6 elements of the touple into the datetime constructor, like: datetime.datetime(*time.strptime("2007-03-04T21:08:12", "%Y-%m-%dT%H:%M:%S")[:6]) ...

Django: overriding 'unoverridable' admin templates per app instead of per project?

The Django documentation states the following clearly: Not every template in contrib\admin\templates\admin may be overridden per app or per model. It then lists the ones that can, and base.html, base_site.html and index.html – the ones I'm interested in – are not among those listed. They can be overridden per-project, but not per-a...

How to ensure that a javascript file is included only once in Django

I have a few child templates which have extraheads which include the jquery script. Sometimes they are used together. How can I have the jquery javascript file loaded only once? If it were convenient to set template variables, I could set and check one before including the line. ...

Template in Django

Inline template In my template can I use a <a href> tag? I want that if there is a field named 'id' it should give a href link over there. I have tried following options: 1){% ifequal field.field.label "Id" %} <a href =../../{{field.field}}>click here </a> 2){% ifequal field.field.label "Id" %} <a href ="../../{{field.field}}">clic...

Django collection selection support?

I am fairly new to Django and I'm curious if some functionality regarding selecting specific collection values in my templates. What I'd like to do is something like this: I have an object called content it has a key and a value property and i have a collection of that content object. I'd like to do something like this in my template: ...

implementing a template tag within a generic app - django

I have developed some code that builds on the contrib comments app, such as handlers for ajax requests. This code is in a separate application, which we can call 'comments2'. the url configuration of the project is structured in such a way that all calls to /comments are directed to this app's views. This works without problems. Very re...

Traversing multi-dimensional dictionary in django

I'm a PHP guy on my first day in Python-land, trying to convert a php site to python (learning experience), and I'm hurting for advice. I never thought it would be so hard to use multi-dimensional arrays or dictionaries as you pythoners call them. So I can create multi-dimensional arrays using this, but i can't loop it in a django templ...

Basic CRUD problem

Hello, I am studying Django, and I met this problem: "Missing id in QueryDict in a multi Dict error". I try to solve this by many ways, including importing the id with 'idzz' into the form built by form.as_table, but at submit time the system sees no id. How can I inject the current id before a save(). I scanned many FAQ's and tutorials...

Traversing foreign key related tables in django templates

View categories = Category.objects.all() t = loader.get_template('index.html') v = Context({ 'categories': categories }) return HttpResponse(t.render(v)) Template {% for category in categories %} <h1>{{ category.name }}</h1> {% endfor %} this works great. now im trying to print each company in that category. the company table...

Linking to the django admin site

Very basic question, but I'm having trouble tracking down the answer on the web. I have a template, which I want to link to the django admin site (i.e. localhost:8000/admin). What is the code for this? I'm imagining something like <a href="{% url admin.site.root %}">link to admin panel</a> However, when I try the above snippet I get:...

Django media URLs in CSS files

In django templates, it's common to do the following: <img src="{{ MEDIA_URL }}/img/someImage.jpg"> How would you accomplish this in a CSS file which is not served as a template? .someClass { /* can't do this this */ background: url("{{ MEDIA_URL }}/img/someImage.jpg"); /* either this */ background: url("http:...

Django: Is there a better way to bold the current page link

I have a base.html template that contains a list of links. Example: <div id="sidebar1"> <ul> <li><a href="/" title="">Index</a></li> <li><a href="/stuff/" title="" class="current">Stuff</a></li> <li><a href="/about/" title="">About Me</a></li> <li><a href="/contact/" title="">Contact Me</a></l...

How can I put a block of dynamically generated content into a django template?

I want to include things like twitter status, or delicious tags, in my django templates. These things are dynamic, yet regular. How would this be done? ...

Django Paginated Comments .. is there any existing solutions?

Hi, is there any existing pagination solution for Django contrib.comments? What I need is just a simple paginated django comments, for the Basic Blog application (from the Django Basic Apps) I used, using a simple has_previous and has_next I have copied the django.contrib.comments and tried modify the code but with no success. The code...

Defining "global variable" in Django templates

I'm doing something like: {% extends 'base.html' %} {% url myapp.views.dashboard object as object_url %} {% block sidebar %} ... {{ object_url }} ... {% endblock %} {% block content %} ... {{ object_url }} ... {% endblock %} Django documentation says url templatetag can define a variable in context, but I don't get any value for objec...

Django template tag for Model query result

I wonna simple tag, for showing table of any model arrays like: {% table city_list %} Do anybody see such things? ...

Django: what does "load" do (in a template file)?

As "load" is far too generic for searching: What is the purpose of "load" and what does it do in this particular case? - in a template file, base_weblog.html, {% load weblog %}{% render_month_links %} Are some naming conventions used in order for "load" to do its job? E.g. names of folders and/or files and/or class names? Where is t...

Why on earth do I have to pass RequestContext in all of my responses?

I want to highlight the current page in the navigation menu. Obviously I need to give the menu links a class like 'active' when you are on their page. This is a classic problem and I've seen many solutions proposed. My problem is I hate all of them and consider none of them to be very DRY. For example: @register.simple_tag def active(re...