I have thought about this, the problem is that part off the context variables are arguments to the view method. So I have urls like "(? P<project>\w+)", and I need to extract the project name from the url to produce the context. So in my context preprocessor to read the url configs, look if a pattern matches the current path, and if it does, extract the project from the url if present in the path. It all seems a bit hackish to me, even though it's possible.
I can proabably also use decorators to achieve the same, but in truth I would prefer it if I could extend some class instead. On Apr 1, 10:51 am, Briel <toppe...@gmail.com> wrote: > Hi. > For the second part, it looks like you could use your own > template_context_preprocessor. With it you can do stuff like > creating variables for your template. Maybe this would be able to > solve your problem having to send the same template vars over and > over again. If you dont need view specific variables, this should do > it. > > You can take a look at the docs about them and how to write > them:http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-... > > ~Jakob > > On 1 Apr., 09:42, Ståle Undheim <staa...@gmail.com> wrote: > > > I come from a Java background, and I really like Apache Wicket as a > > way for constructing web frameworks. In it you use classes, extension > > and compositions to build your pages. This allows for great reuse off > > components in different pages. > > > Django however works via functions instead, which can't be extended. > > And since each function will represent a full page, they seem harder > > to combine together. Maybe the way I am thinking about how to solve > > stuff in Django is too much affected by my Java background, and I am > > not doing things in a Pythonic way. > > > So I have 2 cases, I will explain the problem, how I would solve it in > > Wicket, how I have solved it in Python and the issues I have with the > > solutions. Maybe someone can give me some good pointers and advice > > regarding this. > > > The first thing I have is a file list. I use this in 2 different > > places. The list has some filter checkboxes on top, and a table off > > files, each with a link next to them. In 1 view the link says "view" > > and takes you to viewing the file, in another view it adds the file to > > a selection off files. In Wicket I would make a file list component, > > this had 2 properties you needed to set, link text and onclick > > action. > > > For Django I instead ended up just copying the template and fitting it > > for each case. Each view has a different base template they extend > > which is the context for the application. I also needed to make sure > > the context was correct in each view function. I used some javascript, > > and was able to copy that directly. I really don't like that I have to > > copy the template code around, and match up the view context to this > > template in each case. Is it possible to turn my file list into a > > component with just 1 template and some config, without it being > > excessively verbose? > > > The other thing I have is multiple views in one app that use the same > > base design template. The base design template provides menus related > > to the app, while each view provides the content in the design. Since > > there is common context variables that are needed for the design > > template for each view, each view must include these variables in it's > > context for things to work. Which I again feel like is duplication off > > code. I would instead prefered a base class for the app, that all the > > views in it extended, and thus didn't need to worry about setting up > > the root context correctly. > > > I hope someone can enlighten me about me either being all wrong in how > > I think about app construction, or that there are good elegant > > solutions for these things already available. --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---