Re: multiple views function in a single URL specification
seems like you're over thinking... you want a single url to handle multiple pieces of information? you can assign a single view function to a url. but you can define multiple functions within that view and merely pass them through to the template as part of the response. Or take a look at template tags, as that appears to be more suitable On Oct 17, 1:16 pm, John Yeukhon Wongwrote: > I asked this somewhere else but it seems like the responder hasn't > reply the latest comment I > made.http://stackoverflow.com/questions/3951758/how-do-you-iterate-over-a-... > > Nevertheless, I think I should be welcome to make one here. > > Let's keep thing short. > > Say I have a very simple list to iterate > > [--code--] > def link(request): > c = Context() > c['title'] = ['Home Page', 'Current Time', '10 hours later'] > return render_to_response('time.html', c) > [--code--] > > Now say I also have another view called current_time > > In my html I had, for example > [--code--] > {% for item in title %} > {{item}} > {% if not forloop.last %} | {% endif %} > {% endfor %} > > {% if hour <= 1 %} > do something... > {% endif %} > > [--code--] > > For the template, I tried loop through "in c.title, in c, in title" > and still doesn't work > > As you can guess, I use two view functions in a single html file. > > The problem is that I received 'function' object is not iterable > > So the guy said I probably had a problem with the URL > my URL --> (r'^now/$', current_time, link), > > So he recommended me doing this > (r'^articles/(?P\(?P)/$', > 'project_name.views.link'), #the second tuple element is the view > function > > Something similar to Django URL Dispatcher (from the dispatcher > chapter).. I think... > I think he meant to capture then. But what I want to do is really > just, say, localhost/now/ and load the page > > I can definitely integrate two views functions into one single > function, which works fine. > > The question is, how can I assign multiple views function in a single > URL??? > > Thank you for any input in advance!!! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: multiple views function in a single URL specification
On Oct 17, 6:16 pm, John Yeukhon Wongwrote: > I asked this somewhere else but it seems like the responder hasn't > reply the latest comment I > made.http://stackoverflow.com/questions/3951758/how-do-you-iterate-over-a-... > > Nevertheless, I think I should be welcome to make one here. > > Let's keep thing short. > > Say I have a very simple list to iterate > > [--code--] > def link(request): > c = Context() > c['title'] = ['Home Page', 'Current Time', '10 hours later'] > return render_to_response('time.html', c) > [--code--] > > Now say I also have another view called current_time > > In my html I had, for example > [--code--] > {% for item in title %} > {{item}} > {% if not forloop.last %} | {% endif %} > {% endfor %} > > {% if hour <= 1 %} > do something... > {% endif %} > > [--code--] > > For the template, I tried loop through "in c.title, in c, in title" > and still doesn't work > > As you can guess, I use two view functions in a single html file. > > The problem is that I received 'function' object is not iterable > > So the guy said I probably had a problem with the URL > my URL --> (r'^now/$', current_time, link), > > So he recommended me doing this > (r'^articles/(?P\(?P)/$', > 'project_name.views.link'), #the second tuple element is the view > function > > Something similar to Django URL Dispatcher (from the dispatcher > chapter).. I think... > I think he meant to capture then. But what I want to do is really > just, say, localhost/now/ and load the page > > I can definitely integrate two views functions into one single > function, which works fine. > > The question is, how can I assign multiple views function in a single > URL??? > > Thank you for any input in advance!!! You can't do that, and there isn't any reason to want to do so. A view function takes a request, and returns a response, which is usually in the form of some rendered HTML. How would it work with two? What would be the input to the second function? How would the outputs be merged? As usual, the real question is what are you trying to do that you think would be best solved by having two views for a single URL. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
multiple views function in a single URL specification
I asked this somewhere else but it seems like the responder hasn't reply the latest comment I made. http://stackoverflow.com/questions/3951758/how-do-you-iterate-over-a-... Nevertheless, I think I should be welcome to make one here. Let's keep thing short. Say I have a very simple list to iterate [--code--] def link(request): c = Context() c['title'] = ['Home Page', 'Current Time', '10 hours later'] return render_to_response('time.html', c) [--code--] Now say I also have another view called current_time In my html I had, for example [--code--] {% for item in title %} {{item}} {% if not forloop.last %} | {% endif %} {% endfor %} {% if hour <= 1 %} do something... {% endif %} [--code--] For the template, I tried loop through "in c.title, in c, in title" and still doesn't work As you can guess, I use two view functions in a single html file. The problem is that I received 'function' object is not iterable So the guy said I probably had a problem with the URL my URL --> (r'^now/$', current_time, link), So he recommended me doing this (r'^articles/(?P\(?P)/$', 'project_name.views.link'), #the second tuple element is the view function Something similar to Django URL Dispatcher (from the dispatcher chapter).. I think... I think he meant to capture then. But what I want to do is really just, say, localhost/now/ and load the page I can definitely integrate two views functions into one single function, which works fine. The question is, how can I assign multiple views function in a single URL??? Thank you for any input in advance!!! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: multiple views function in a single URL specification
I think for the link view function, I need to do something like this instead. Sorry. [--code--] def link(request): c = Context() c['title'] = ['Home Page', 'Current Time', '10 hours later'] return render_to_response('time.html', c) [--code--] On Oct 17, 1:06 pm, John Yeukhon Wongwrote: > I asked this somewhere else but it seems like the responder hasn't > reply the latest comment I > made.http://stackoverflow.com/questions/3951758/how-do-you-iterate-over-a-... > > Nevertheless, I think I should be welcome to make one here. > > Let's keep thing short. > > Say I have a very simple list to iterate > > [--code--] > def link(request): > title = ['Home Page', 'Current Time', '10 hours later'] > return render_to_response('time.html', title) > [--code--] > > Now say I also have another view called current_time > > In my html I had, for example > [--code--] > {% for item in title %} > {{item}} > {% if not forloop.last %} | {% endif %} > {% endfor %} > > {% if hour <= 1 %} > do something... > {% endif %} > > [--code--] > > As you can guess, I use two view functions in a single html file. > > The problem is that I received 'function' object is not iterable > > So the guy said I probably had a problem with the URL > my URL --> (r'^now/$', current_time, link), > > So he recommended me doing this > (r'^articles/(?P\(?P)/$', > 'project_name.views.link'), #the second tuple element is the view > function > > Something similar to Django URL Dispatcher (from the dispatcher > chapter).. I think... > I think he meant to capture then. But what I want to do is really > just, say, localhost/now/ and load the page > > I can definitely integrate two views functions into one single > function, which works fine. > > The question is, how can I assign multiple views function in a single > URL??? > > Thank you for any input in advance!!! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
multiple views function in a single URL specification
I asked this somewhere else but it seems like the responder hasn't reply the latest comment I made. http://stackoverflow.com/questions/3951758/how-do-you-iterate-over-a-list-in-django/3951775#3951775 Nevertheless, I think I should be welcome to make one here. Let's keep thing short. Say I have a very simple list to iterate [--code--] def link(request): title = ['Home Page', 'Current Time', '10 hours later'] return render_to_response('time.html', title) [--code--] Now say I also have another view called current_time In my html I had, for example [--code--] {% for item in title %} {{item}} {% if not forloop.last %} | {% endif %} {% endfor %} {% if hour <= 1 %} do something... {% endif %} [--code--] As you can guess, I use two view functions in a single html file. The problem is that I received 'function' object is not iterable So the guy said I probably had a problem with the URL my URL --> (r'^now/$', current_time, link), So he recommended me doing this (r'^articles/(?P\(?P)/$', 'project_name.views.link'), #the second tuple element is the view function Something similar to Django URL Dispatcher (from the dispatcher chapter).. I think... I think he meant to capture then. But what I want to do is really just, say, localhost/now/ and load the page I can definitely integrate two views functions into one single function, which works fine. The question is, how can I assign multiple views function in a single URL??? Thank you for any input in advance!!! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.