Re: Best Practices in Implementing Mini-Content Boxes Across the Site
+1 - thanks to Ronny, Bruno and Daniel's advice in this thread. It helps sometimes to have pointers to info/tools in the context of a problem, even if I was vaguely aware of the info/tools before. On Thu, Oct 16, 2008 at 4:30 AM, Israel Dacanay Canasa <[EMAIL PROTECTED]>wrote: > > Bruno, > > Thanks a lot! > > I didn't know that Django will include the templatetags of all apps > mentioned in settings.py. I thought that templatetags are included > only within the context of the current app accessed by the browser. > > Now everything looks clearer, and I feel that I just got out from > being a newbie, because this information gave me an idea on how to do > almost all the things that I want for my project. > > Thank you so much! > > Israel Dacanay Canasa > - > Email: [EMAIL PROTECTED] > Cel #: +63917-404-8030 > Phone #: +632-567-2635 > > On 10 16, 08, at 7:12 PM, bruno desthuilliers wrote: > > > > > On 16 oct, 12:34, raeldc <[EMAIL PROTECTED]> wrote: > >> Hello Again Guys! > >> > >> With your guidance, I was able to get a pretty good idea on how to > >> put > >> mini-content boxes on my website. > >> > >> However, one thing I realized (with my still limited understanding of > >> Django), is that templatetags are actually coupled with apps. To > >> create templatetags, I must make it as a templatetags module inside > >> my > >> apps. It doesn't look "loosely coupled" to me if I want to reuse the > >> same templatetag on different apps. > > > > It's just like for any function/class/whatever you want to make > > reusable in different contexts : put it in a separate package / > > module / app. > > > > Since indeed Django requires templatetags to live in a "django > > application" - that is, a python package with a more or less defined > > layout -, then the solution is obvious: > > > > - start a new 'mycustomtags' app > > - move your templatetags to this app > > - put that app somewhere in your PYTHONPATH (apps don't have to live > > in your project, cf django.contrib.XXX apps) > > - and of course mention that app in your project > > settings.INSTALLED_APPS > > > > Note that just any 'component' of a django app is optional. IOW, you > > don't have to have models AND views AND urls AND whatnot - just put > > what makes sense. In your case, your mycustomtemplatetags app layout > > would only contain the mandatory[1] top-level __init__.py, the > > templatetags directory - with it's own mandatory __init__.py -, and > > your templatetags file(s). FWIW, that's just what the template_utils > > app do: > > http://code.google.com/p/django-template-utils/ > > > > 1] mandatory to make Python consider this directory as a Python > > package. > > > > HTH > > > > > > > > > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Practices in Implementing Mini-Content Boxes Across the Site
Bruno, Thanks a lot! I didn't know that Django will include the templatetags of all apps mentioned in settings.py. I thought that templatetags are included only within the context of the current app accessed by the browser. Now everything looks clearer, and I feel that I just got out from being a newbie, because this information gave me an idea on how to do almost all the things that I want for my project. Thank you so much! Israel Dacanay Canasa - Email: [EMAIL PROTECTED] Cel #: +63917-404-8030 Phone #: +632-567-2635 On 10 16, 08, at 7:12 PM, bruno desthuilliers wrote: > > On 16 oct, 12:34, raeldc <[EMAIL PROTECTED]> wrote: >> Hello Again Guys! >> >> With your guidance, I was able to get a pretty good idea on how to >> put >> mini-content boxes on my website. >> >> However, one thing I realized (with my still limited understanding of >> Django), is that templatetags are actually coupled with apps. To >> create templatetags, I must make it as a templatetags module inside >> my >> apps. It doesn't look "loosely coupled" to me if I want to reuse the >> same templatetag on different apps. > > It's just like for any function/class/whatever you want to make > reusable in different contexts : put it in a separate package / > module / app. > > Since indeed Django requires templatetags to live in a "django > application" - that is, a python package with a more or less defined > layout -, then the solution is obvious: > > - start a new 'mycustomtags' app > - move your templatetags to this app > - put that app somewhere in your PYTHONPATH (apps don't have to live > in your project, cf django.contrib.XXX apps) > - and of course mention that app in your project > settings.INSTALLED_APPS > > Note that just any 'component' of a django app is optional. IOW, you > don't have to have models AND views AND urls AND whatnot - just put > what makes sense. In your case, your mycustomtemplatetags app layout > would only contain the mandatory[1] top-level __init__.py, the > templatetags directory - with it's own mandatory __init__.py -, and > your templatetags file(s). FWIW, that's just what the template_utils > app do: > http://code.google.com/p/django-template-utils/ > > 1] mandatory to make Python consider this directory as a Python > package. > > HTH > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Practices in Implementing Mini-Content Boxes Across the Site
On 16 oct, 12:34, raeldc <[EMAIL PROTECTED]> wrote: > Hello Again Guys! > > With your guidance, I was able to get a pretty good idea on how to put > mini-content boxes on my website. > > However, one thing I realized (with my still limited understanding of > Django), is that templatetags are actually coupled with apps. To > create templatetags, I must make it as a templatetags module inside my > apps. It doesn't look "loosely coupled" to me if I want to reuse the > same templatetag on different apps. It's just like for any function/class/whatever you want to make reusable in different contexts : put it in a separate package / module / app. Since indeed Django requires templatetags to live in a "django application" - that is, a python package with a more or less defined layout -, then the solution is obvious: - start a new 'mycustomtags' app - move your templatetags to this app - put that app somewhere in your PYTHONPATH (apps don't have to live in your project, cf django.contrib.XXX apps) - and of course mention that app in your project settings.INSTALLED_APPS Note that just any 'component' of a django app is optional. IOW, you don't have to have models AND views AND urls AND whatnot - just put what makes sense. In your case, your mycustomtemplatetags app layout would only contain the mandatory[1] top-level __init__.py, the templatetags directory - with it's own mandatory __init__.py -, and your templatetags file(s). FWIW, that's just what the template_utils app do: http://code.google.com/p/django-template-utils/ 1] mandatory to make Python consider this directory as a Python package. HTH --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Practices in Implementing Mini-Content Boxes Across the Site
Hello Again Guys! With your guidance, I was able to get a pretty good idea on how to put mini-content boxes on my website. However, one thing I realized (with my still limited understanding of Django), is that templatetags are actually coupled with apps. To create templatetags, I must make it as a templatetags module inside my apps. It doesn't look "loosely coupled" to me if I want to reuse the same templatetag on different apps. For example, the tip Daniel gave me at http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/ teaches how to create a "get_latest" tag which can be configured by passing arguments to it from the template. But the "get_latest" tag would only be coupled with the app where I created it. Even though it can use different models from different apps. To use it on a different app, I must rewrite the same templatetag module in another app. This doesn't look DRY to me. So I think my idea on creating mini-content boxes is wrong because my way is not DRY and Loosely Coupled. I hope you can enlighten me on this one. Thank you! On Oct 13, 11:02 pm, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 13 oct, 10:38, raeldc <[EMAIL PROTECTED]> wrote: > (snip) > > > One of the things I'm wondering about is how to implementmini-content > > boxes. It is known to Joomla as modules, in Drupal as blocks, to > > others they are called widgets or side bars. In CMS systems, I can > > assign acontent-box to be viewable on different pages or all pages > > with simple point and click. In Django, I think I would have to call > > the VIEW for thosecontentboxes in every VIEW where I want them > > displayed. This method looks very redundant to me. Or maybe I'm still > > in the stage of my learning where I haven't found the Django way that > > deals with this. So I'm asking the experts on Django for guidance. How > > do I implement easily manageable min-contentboxes on my Django > > website? Is there a Django standard way? If none, can you please > > suggest what you think is the best way to do this? > > There are/have been a couple efforts in this direction already. One of > them seems to be abandonned by it's author, but could be reused as a > basis for what you're after:http://code.google.com/p/django-modular/ > > The other one seems much more alive, but barely documented at > all:http://code.google.com/p/django-app-plugins/ > > HTH --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Practices in Implementing Mini-Content Boxes Across the Site
On 13 oct, 10:38, raeldc <[EMAIL PROTECTED]> wrote: (snip) > One of the things I'm wondering about is how to implement mini-content > boxes. It is known to Joomla as modules, in Drupal as blocks, to > others they are called widgets or side bars. In CMS systems, I can > assign a content-box to be viewable on different pages or all pages > with simple point and click. In Django, I think I would have to call > the VIEW for those content boxes in every VIEW where I want them > displayed. This method looks very redundant to me. Or maybe I'm still > in the stage of my learning where I haven't found the Django way that > deals with this. So I'm asking the experts on Django for guidance. How > do I implement easily manageable min-content boxes on my Django > website? Is there a Django standard way? If none, can you please > suggest what you think is the best way to do this? There are/have been a couple efforts in this direction already. One of them seems to be abandonned by it's author, but could be reused as a basis for what you're after: http://code.google.com/p/django-modular/ The other one seems much more alive, but barely documented at all: http://code.google.com/p/django-app-plugins/ HTH --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Practices in Implementing Mini-Content Boxes Across the Site
Daniel, thank you so much! Your answer opened a whole box of new ideas I'd like to try. Thanks everyone! Rael On Oct 13, 5:19 pm, Daniel Roseman <[EMAIL PROTECTED]> wrote: > On Oct 13, 9:38 am, raeldc <[EMAIL PROTECTED]> wrote: > > > > > Hi Guys, > > > I'm a Programmer coming from a Joomla! CMS background ( I develop > > Joomla extensions). I took notice of Django when I'm looking for other > > alternatives to build mission critical Web Apps, because it's clear to > > me that Joomla and PHP will not be enough to do the job. > > > I'm now learning Django in depth and I think I can now build a decent > > basic website comparable to what I can do with Joomla. However, since > > I'm a Django/Python noob, I don't know how to implement some things in > > the best Django-pythonic way. > > > One of the things I'm wondering about is how to implement mini-content > > boxes. It is known to Joomla as modules, in Drupal as blocks, to > > others they are called widgets or side bars. In CMS systems, I can > > assign a content-box to be viewable on different pages or all pages > > with simple point and click. In Django, I think I would have to call > > the VIEW for those content boxes in every VIEW where I want them > > displayed. This method looks very redundant to me. Or maybe I'm still > > in the stage of my learning where I haven't found the Django way that > > deals with this. So I'm asking the experts on Django for guidance. How > > do I implement easily manageable min-content boxes on my Django > > website? Is there a Django standard way? If none, can you please > > suggest what you think is the best way to do this? > > > Thank you! > > The best way to do this is via custom template tags, which are > basically just bits of code that you can insert in any template. > They're in the documentation > here:http://docs.djangoproject.com/en/dev/howto/custom-template-tags/ > - read the whole thing, but you want an 'inclusion tag' which is a > shortcut to render a template snippet with its own context. > > James Bennett has a great how-to on this (it's slightly out of date as > it doesn't mention the shortcuts, but the gist of it is still > valid):http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-tem... > > And I disagree with Olivier that this is verbose and cumbersome: you > can write this sort of thing in about three lines if you use the > decorators. > -- > 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-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Practices in Implementing Mini-Content Boxes Across the Site
On Oct 13, 9:38 am, raeldc <[EMAIL PROTECTED]> wrote: > Hi Guys, > > I'm a Programmer coming from a Joomla! CMS background ( I develop > Joomla extensions). I took notice of Django when I'm looking for other > alternatives to build mission critical Web Apps, because it's clear to > me that Joomla and PHP will not be enough to do the job. > > I'm now learning Django in depth and I think I can now build a decent > basic website comparable to what I can do with Joomla. However, since > I'm a Django/Python noob, I don't know how to implement some things in > the best Django-pythonic way. > > One of the things I'm wondering about is how to implement mini-content > boxes. It is known to Joomla as modules, in Drupal as blocks, to > others they are called widgets or side bars. In CMS systems, I can > assign a content-box to be viewable on different pages or all pages > with simple point and click. In Django, I think I would have to call > the VIEW for those content boxes in every VIEW where I want them > displayed. This method looks very redundant to me. Or maybe I'm still > in the stage of my learning where I haven't found the Django way that > deals with this. So I'm asking the experts on Django for guidance. How > do I implement easily manageable min-content boxes on my Django > website? Is there a Django standard way? If none, can you please > suggest what you think is the best way to do this? > > Thank you! The best way to do this is via custom template tags, which are basically just bits of code that you can insert in any template. They're in the documentation here: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/ - read the whole thing, but you want an 'inclusion tag' which is a shortcut to render a template snippet with its own context. James Bennett has a great how-to on this (it's slightly out of date as it doesn't mention the shortcuts, but the gist of it is still valid): http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/ And I disagree with Olivier that this is verbose and cumbersome: you can write this sort of thing in about three lines if you use the decorators. -- 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-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Practices in Implementing Mini-Content Boxes Across the Site
> One of the things I'm wondering about is how to implement mini-content > boxes. It is known to Joomla as modules, in Drupal as blocks, to > others they are called widgets or side bars. In pure Django, you would have to write a "template tag", see the doc for this. It's Django's equivalent for macros and it's rather verbose and cumbersome. For ease and simplicity, consider using another template engine within Django, like Mako or Jinja2 (even if it's probably not the "best Django-pythonic way" :) Regards, Olivier --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Best Practices in Implementing Mini-Content Boxes Across the Site
On Mon, Oct 13, 2008 at 3:38 PM, raeldc <[EMAIL PROTECTED]> wrote: > One of the things I'm wondering about is how to implement mini-content > boxes. It is known to Joomla as modules, in Drupal as blocks, to > others they are called widgets or side bars. In CMS systems, I can > assign a content-box to be viewable on different pages or all pages > with simple point and click. In Django, I think I would have to call > the VIEW for those content boxes in every VIEW where I want them > displayed. This method looks very redundant to me. Or maybe I'm still > in the stage of my learning where I haven't found the Django way that > deals with this. So I'm asking the experts on Django for guidance. How > do I implement easily manageable min-content boxes on my Django > website? Is there a Django standard way? If none, can you please > suggest what you think is the best way to do this? I don't think there's a standard, since Django is not a CMS (you build your CMS *with* Django), and therefore it doesn't provide any CMS-specific things like sidebars, widgets, boxes, or whatever it is called. However, Django templates supports inheritance and a way to include other templates that should make it easier: http://docs.djangoproject.com/en/dev/topics/templates/#id1 http://docs.djangoproject.com/en/dev/ref/templates/builtins/#include For static blocks, there's also a 3rd party project called django-chunks that you might want to take a look at. Ronny --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Best Practices in Implementing Mini-Content Boxes Across the Site
Hi Guys, I'm a Programmer coming from a Joomla! CMS background ( I develop Joomla extensions). I took notice of Django when I'm looking for other alternatives to build mission critical Web Apps, because it's clear to me that Joomla and PHP will not be enough to do the job. I'm now learning Django in depth and I think I can now build a decent basic website comparable to what I can do with Joomla. However, since I'm a Django/Python noob, I don't know how to implement some things in the best Django-pythonic way. One of the things I'm wondering about is how to implement mini-content boxes. It is known to Joomla as modules, in Drupal as blocks, to others they are called widgets or side bars. In CMS systems, I can assign a content-box to be viewable on different pages or all pages with simple point and click. In Django, I think I would have to call the VIEW for those content boxes in every VIEW where I want them displayed. This method looks very redundant to me. Or maybe I'm still in the stage of my learning where I haven't found the Django way that deals with this. So I'm asking the experts on Django for guidance. How do I implement easily manageable min-content boxes on my Django website? Is there a Django standard way? If none, can you please suggest what you think is the best way to do this? Thank you! --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---