Reputation: 2589
I want create a project where every user can have his own 'homepage'. So I want to be able to set a template for each user and show it on his home page url. Do I just save the template name in the user profile and pass it to the template loader or is there a better / more secure / more plugable way to do this ?
Upvotes: 0
Views: 159
Reputation: 23871
Sounds like you want to allow user to pick up his/her favorite template and set bunches of preferences such as background image, displaying style and so on? If so, your solution is fine. Actually, you are allowing users to choose among provided (and extendable) set of template, instead of allowing them to totally take control of template to use.
Furthermore, for preference settings, which are only used for each user. You might want to save them in serialized field such as jsonfield or picklefield instead of store them per column. I'm writing an app to ease the editing of such fields.
Upvotes: 1
Reputation: 13624
Saving the template name in the user profile is fine. Like you say, you can just pass it to the template render method.
But watch out with one thing: the user should not be able to type in a template name by hand. It should be a choice field for security reason, I think. See at the end of https://docs.djangoproject.com/en/1.4/ref/models/fields/#choices, you can make the list of template choices dynamic.
Upvotes: 1