简体   繁体   中英

Dynamic templates in Django

I'm about to make a dynamic website in Django so that user can change the template the website is based upon....for new users, they'll have to choose a template they like from a menu, after which this is stored in a cookie for future reference. I however don't know how to do this....any ideas.

Templates are text files in a directory on your server.

The menu is a list of directories.

The specific template to be loaded is named in your render_to_response calls in each view function.

It's wonderfully quite simple and elegant.

You never need to do a template "swap". You can simply have all the templates you ever want in a template search path. All can be available to all users at all times. You just provide directory_name/template_name . All handled for you.

Don't mess with explicit cookies. Django already does this for you. See chapter 12 of the Django Book.

Use the Profiles extension and put the selected template directory name in the user's profile.

When user selects a template, store the template name/ some sort of alias in the cookie. When the user loads the page again, in the view function, check for template identifier in the cookie. If the identifier is present, retrieve the actual template path and pass it to the render_to_response function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM