how to get value of anchor tag which is taken from database using python.

795 views
Skip to first unread message

Avnesh Shakya

unread,
Mar 8, 2013, 4:07:12 AM3/8/13
to django...@googlegroups.com
I am using an anchor tag and have to access its content in python. I have to access the 'text' from this.

in html page--

{% for c in courses%}
<tr>
<div><td><b><I>{{c.title}}</I></b></td><td><a href="cd.html">{{c.stream}}</a></td><td><b><I>

i want to get {{c.stream}} value so that i can use it in views.py i want to filter the content acoording to it, and want to display after shorting acc. it.....

plz help me...

thanks 

Daniel Roseman

unread,
Mar 8, 2013, 4:38:21 AM3/8/13
to django...@googlegroups.com
It's very unclear what you want to do. But I suspect you should be trying to use that parameter as part of your URL:

    <a href="cd/{{ c.stream }}/">{{ c.stream }}</a>

Or even better, use the {% url %} tag to calculate the correct URL.
--
DR. 

Roberto López López

unread,
Mar 8, 2013, 5:07:25 AM3/8/13
to django...@googlegroups.com

Hi,

How can I iterate over several list objects available in my template?
I'd like to avoid having to concatenate them in the view and pass that
as another parameter.

I mean something like this:

{% for x in list1, list2, list3... listN %}
{% if not forloop.first %}, {% endif %}write some stuff
{% endfor %}

Thanks for your input!

Roberto


Avnesh Shakya

unread,
Mar 8, 2013, 5:10:12 AM3/8/13
to django...@googlegroups.com
Actually, i have lot of different-2 stream, now i want to make it as link, so that i can click on particular stream and it should filter data according to that stream({{c.stream}}) on same page.

thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Avnesh Shakya

unread,
Mar 8, 2013, 6:10:10 AM3/8/13
to django...@googlegroups.com
ya i got it ....
I used   <td><a href="/{{ c.stream }}">{{ c.stream }}</a></td>

and in url -   
                      url(r'^(?P<detail>[^/]+)/$','stream',name="stream"),

      so here detail will store that value...

and in views- 
def stream(request,detail):
    courses = Course.objects.filter(stream = detail )
    ctx = {'courses':courses}
    return render_to_response('homepage/index.html', ctx)

thanks
regards,
avnesh shakya

Javier Guerra Giraldez

unread,
Mar 8, 2013, 9:12:36 AM3/8/13
to django...@googlegroups.com
On Fri, Mar 8, 2013 at 5:07 AM, Roberto López López
<robert...@uni.no> wrote:
> I'd like to avoid having to concatenate them in the view and pass that
> as another parameter.


two ideas come to mind:

- itertools.chain() on the view. it's equivalent to concatenating,
but done lazily, so there's _very_ little overhead.

- add them in the template. the 'add' filter is supposed to work with
lists too.

needless to say, i'd far prefer the first option. view functions are
supposed to gather and organize all the info and templates should have
as little behaviour as possible.


--
Javier

Roberto López López

unread,
Mar 8, 2013, 9:47:30 AM3/8/13
to django...@googlegroups.com

Thank you very much!


On 03/08/2013 03:12 PM, Javier Guerra Giraldez wrote:
> On Fri, Mar 8, 2013 at 5:07 AM, Roberto L�pez L�pez
Reply all
Reply to author
Forward
0 new messages