Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Is this a good practice, or is it just plain stupid? [RSS Feed]

#1 Dec. 7, 2010 22:12:06

Big Y.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Is this a good practice, or is it just plain stupid?


Hi everyone,


I hope that this group is the good one for this kind of questions.
So today, I decided to write a tiny django app (in less than 5 minutes
actually) that
helps me add views arguments to templates contexts automatically.


For eg.



def latest_tagged_objects(request, obj, limit, tag): """ Displays
the 'limit' latest objects 'obj' tagged with 'tag' """ # Retrieve these
objects #create a context that will include the args passed to this
view along with #other variables context = dict( obj=obj, limit=limit,
tag=tag, #Other variables here )




I do this often. i.e. add views arguments to my context, so I wanted to
write a

middleware and a context processor that will do it for me.

I wrote this:https://github.com/initpy/django-viewctxWith this app I can omit 'obj', 'limit', and 'tag' in the previous

dict and have them available in my template as: {{view.kwargs.obj}},
{{view.kwargs.limit}}

and {{view.kwargs.tag}}




It was so simple that I'm still wondering if it is a good practice or
just stupid.




Thanks for your help and suggestions!

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Is this a good practice, or is it just plain stupid? [RSS Feed]

Board footer

Moderator control

Enjoy the 13th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support