Re: home page menu view variables cross every view?
Works great! Thank you very much! Goran On Sep 8, 3:51 pm, bagheerawrote: > Dnia 08-09-2010 o 15:41:13 Goran napisał(a): > > > > > Thanks for your help but I think that understand how template works. > > My menu is drop down menu with menu items which comes from variable > > {{ for menuitem in myvariable }} > > {{ menuitem.title }} > > {{ endfor }} > > > and myvariable is in my view: > > myvariable = Item.objects.all() > > > So if I extend base.html menu is there, but menu items are not, > > because "myvariable" come from the "view". So seems that I need > > "myvariable = Item.objects.all()" in every view on the site. Which > > also means that I need to repeat myself about 20 times. I was > > wondering is there any solution to include myvariable in settings file > > or something? Also is there any solution to extend flatpage view with > > myvariable? > > > Thanks > > http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-c... > > You can write ur own context processor, witch variables will be accessible > across all templates. > > Example code: > content.py file: > > from nml.newsletter.forms import NewsletterForm > > def newsletter_form(request): > """ > Creates unbound newsletter form > """ > nl_form = NewsletterForm() > return {'nl_form' : nl_form} > > in settings.py: > > TEMPLATE_CONTEXT_PROCESSORS = ( > "django.contrib.auth.context_processors.auth", > "django.core.context_processors.debug", > "django.core.context_processors.i18n", > "django.core.context_processors.media", > "django.contrib.messages.context_processors.messages", > 'static_content.newsletter_form', > ) > > I used that once in root template, but it is rendered with any view that > extends my root template > -- > Linux user -- 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: home page menu view variables cross every view?
Dnia 08-09-2010 o 15:41:13 Gorannapisał(a): Thanks for your help but I think that understand how template works. My menu is drop down menu with menu items which comes from variable {{ for menuitem in myvariable }} {{ menuitem.title }} {{ endfor }} and myvariable is in my view: myvariable = Item.objects.all() So if I extend base.html menu is there, but menu items are not, because "myvariable" come from the "view". So seems that I need "myvariable = Item.objects.all()" in every view on the site. Which also means that I need to repeat myself about 20 times. I was wondering is there any solution to include myvariable in settings file or something? Also is there any solution to extend flatpage view with myvariable? Thanks http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-context-requestcontext You can write ur own context processor, witch variables will be accessible across all templates. Example code: content.py file: from nml.newsletter.forms import NewsletterForm def newsletter_form(request): """ Creates unbound newsletter form """ nl_form = NewsletterForm() return {'nl_form' : nl_form} in settings.py: TEMPLATE_CONTEXT_PROCESSORS = ( "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.contrib.messages.context_processors.messages", 'static_content.newsletter_form', ) I used that once in root template, but it is rendered with any view that extends my root template -- Linux user -- 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: home page menu view variables cross every view?
Thanks for your help but I think that understand how template works. My menu is drop down menu with menu items which comes from variable {{ for menuitem in myvariable }} {{ menuitem.title }} {{ endfor }} and myvariable is in my view: myvariable = Item.objects.all() So if I extend base.html menu is there, but menu items are not, because "myvariable" come from the "view". So seems that I need "myvariable = Item.objects.all()" in every view on the site. Which also means that I need to repeat myself about 20 times. I was wondering is there any solution to include myvariable in settings file or something? Also is there any solution to extend flatpage view with myvariable? Thanks -- 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: home page menu view variables cross every view?
You can use your own template for flatpages, see http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/?from=olddocs#flatpage-templates Just make that menu a separate template and include it wherever you want. Of course your flatpages template and your other templates can inherit from the same base where the menu is included. I don't know what you mean by "place these variables ( db queries)"? Anyway if your menu is generated from a database and it won't change often it's a good idea to wrap such template code in a cache tag, especially if you make manny queries to generate that menu. On Tue, Sep 7, 2010 at 8:55 PM, Goranwrote: > I'm Django novice and I want to have some menu (top menu) which have > some dynamically populated items. So inside home page view I have some > variables to get these menu items. But because it's top menu I need it > on every page on the site and i have about 20 views. So I'm place > these variables ( db queries) in every view on the site. It works > except on the Flatpages because I can't find a way to extend Flatpage > view with these variables. Now I have two questions: > > 1. How can I extend FlatPage view to get these menu variables on the > flatpages. > 2. Am I miss something? What's happen with D.R.Y. if I need to place > the same variables on the every view and repeat myself 20 times? > > Any advice? > Thanks > > -- > 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. > > -- 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: home page menu view variables cross every view?
On Tue, Sep 7, 2010 at 8:55 PM, Goranwrote: > I'm Django novice and I want to have some menu (top menu) which have > some dynamically populated items. So inside home page view I have some > variables to get these menu items. But because it's top menu I need it > on every page on the site and i have about 20 views. So I'm place > these variables ( db queries) in every view on the site. It works > except on the Flatpages because I can't find a way to extend Flatpage > view with these variables. Now I have two questions: > > 1. How can I extend FlatPage view to get these menu variables on the > flatpages. > 2. Am I miss something? What's happen with D.R.Y. if I need to place > the same variables on the every view and repeat myself 20 times? > > Any advice? > Thanks Hi, whats about extending? for example base.html? Could this be a way to solve your problem? http://stackoverflow.com/questions/671369/django-specifying-a-base-template-by-directory A live example and pretty cool explanation can be seen in this screencast(s): http://showmedo.com/videotutorials/series?name=PPN7NA155 (The mentioned project is not available anymore but the principles are pretty clear explained. I think extending is shown in episode 3.) good luck TR > > -- > 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. > > -- --- http://thoreg.org --- -- 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.
home page menu view variables cross every view?
I'm Django novice and I want to have some menu (top menu) which have some dynamically populated items. So inside home page view I have some variables to get these menu items. But because it's top menu I need it on every page on the site and i have about 20 views. So I'm place these variables ( db queries) in every view on the site. It works except on the Flatpages because I can't find a way to extend Flatpage view with these variables. Now I have two questions: 1. How can I extend FlatPage view to get these menu variables on the flatpages. 2. Am I miss something? What's happen with D.R.Y. if I need to place the same variables on the every view and repeat myself 20 times? Any advice? Thanks -- 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.