On Fri, Aug 29, 2008 at 11:22 PM, Martin Diers <[EMAIL PROTECTED]> wrote: > > On Aug 29, 2008, at 2:22 PM, Benjamin Buch wrote: > >> >> Clumsy subject, I know... >> >> I know there was a recent discussion about this, but I lost it, so >> sorry for asking again. >> So here's the question: >> >> How can you allow your users to add something like pictures into >> something like blog posts? >> Not just below or above (this could be achieved by a simple foreignkey >> I guess...), but at positions they want to? >> >> Antoher related question would be if it's possible to include tags and >> variables ({{ somevariable }}) into text I enter into the admin? >> >> -benjamin >> > > > Yes, and yes, and the solution is both cases is the same. > > As to how to get the image up there and reference it, here's a > suggestion: Create a model just for images, a form for users to upload > images, and a custom tag which I can then use to insert an image by > name. They can then use the tag in the blog post to include the image. > > To allow tags to be used in content areas, including what you add in > the admin, you will need to double-render your page. > > Like this: > > my_context = {'blah': 'blah'} > output = render_to_string('my_template.html', my_context) > t = Template(output) > HttpResponse(t.render()) >
That's a really bad idea. Users can bring the whole site down with malformed content if you do it like that. At least you should do something like that: try: usercontent = render_to_string('whatever.html', {...}) except TemplateSynatxError: # maybe other exceptions? usercontent = '' render_to_response('main.html', { 'usercontent': usercontent, }) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---