<p>I need to perform a filtered query from within a django template, to get a set of objects equivalent to python code within a view:</p>

<pre><code>queryset = Modelclass.objects.filter(somekey=foo)
</code></pre>

<p>In my template I would like to do</p>

<pre><code>{% for object in data.somekey_set.FILTER %}
</code></pre>

<p>but I just can't seem to find out how to write FILTER.</p>

You can't do this, which is by design.  The Django framework authors intended a strict separation of presentation code from data logic.  Filtering models is data logic, and outputting HTML is presentation logic.
So you have several options.  The easiest is to do the filtering, then pass the result to
```
render_to_response
```
.  Or you could write a method in your model so that you can say
```
{% for object in data.filtered_set %}
```
.  Finally, you could write your own template tag, although in this specific case I would advise against that.