Re: Passing variables to the template... I've having logic problems

2011-04-15 Thread Karen McNeil
Yes, that worked.  Thank you!

Of course, now that I fixed that, I have to deal with the other
problem that I was avoiding... But I'll post that in a different
question.  :-)

Thanks again, Pedro.


On Apr 15, 9:35 pm, Pedro Kroger  wrote:
> You can try something like:
>
> def my_view(request):
>       ...
>
>     context = []
>     for offset in offsets:
>         before = ' '.join(tokens[offset-5:offset])
>         word = tokens[offset]
>         after = ' '.join(tokens[offset+1:offset+5])
>         context.append(before, word, after)
>
>     ...  ...
>
>     return render_to_response("template.html", {'context': context})
>
> Now your data will be available inside the 'context' variable and you
> can access the 'context' variable in your template like you want. I
> hope that helps.
>
> Pedro
>
> --http://pedrokroger.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Passing variables to the template... I've having logic problems

2011-04-15 Thread Pedro Kroger
You can try something like:

def my_view(request):
  ...

context = []
for offset in offsets:
before = ' '.join(tokens[offset-5:offset])
word = tokens[offset]
after = ' '.join(tokens[offset+1:offset+5])
context.append(before, word, after)

...  ...

return render_to_response("template.html", {'context': context})

Now your data will be available inside the 'context' variable and you
can access the 'context' variable in your template like you want. I
hope that helps.

Pedro

-- 
http://pedrokroger.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Passing variables to the template... I've having logic problems

2011-04-15 Thread Karen McNeil
I'm trying to make a concordance (ie, a list of a certain searchterm,
including its surrounding context) and I can get it to work in the
interpreter, but I'm having problems figuring out how to make it a
list that I can pass it to the template.  This is what works in the
interpreter (tokens is a list of words which can be accessed by an
index number, and offset is the index number corresponding to the
searchterm):

>>> for offset in offsets:
... before = ' '.join(tokens[offset-5:offset])  #Takes the
five preceding words and joins them in a string
... word = tokens[offset] #The
searchterm occurance
... after = ' '.join(tokens[offset+1:offset+5])#The five
words after the searchterm
... print "%s %s %s" % (before, word, after)
...
حنانلافاقتزاهيةتبرلي برشه وسيلة في العادة بكوشة
فيهاشويةمشاكلوطلبةوشوية برشه حاجات يعني وكما تعرف
يلقىحلعلىالخاطرتوا برشه ناس كما نحنا هكه
بالكلّوالبلادقاعدةتخسرفي برشه م الشباب متاعها على
كانطحانغيرهاوينوفمّه برشه ممّن تسّوللهم انفسهم الرخيصه

I know you can't read the Arabic output that's written there, but it's
exactly as it should be. Any way I've tried to get the before, word,
after returned as variables (or lists of variables) so I can pass them
to the template, it doesn't work.

What I want to be able to do is something like this:
{% for before, word, after in context %}
{{ before }} {{ word }} {{ after }}
{% endfor %}

I just can't figure out how to do it... Can anyone point me in the
right direction?

Thanks,
Karne

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.