Re: Pass template tags through TextField?

2009-07-22 Thread Ogre

Perfect.  Thanks, Dan.


On Jul 22, 10:23 am, Dan Harris  wrote:
> That shouldn't be a problem, after all templates are just strings as
> are textfields.
>
> If you have a model with your textfield in it as so:
>
> class MyModel(models.Model):
>    template = models.TextField()
>
> and you have a view which renders the template defined in the next
> field
>
> def my_view(request):
>    m = MyModel.objects.get(pk=1)  # for example the first one
>
>    t = Template(m.template)  #this creates a template from your string
> in the model
>    c = Context({'form': form, etc.. #any context to go into the
> template})
>
>   # now you can just return the rendered template as html
>   return HttpResponse(t.render(c))
>
> For more info refer 
> to:http://docs.djangoproject.com/en/dev/ref/request-response/
>
> Cheers,
>
> Dan
>
> On Jul 22, 12:49 pm, Ogre  wrote:
>
> > I have a model where I need to be able to insert template tags into a
> > TextField in the admin as part of the content and then have them
> > rendered properly on the front-end.
>
> > Can this be done?  And if so, can someone recommend a method?  I
> > understand the security concerns of opening that field up to python.
>
> > Thanks in advance.
>
>
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Pass template tags through TextField?

2009-07-22 Thread Dan Harris

That shouldn't be a problem, after all templates are just strings as
are textfields.

If you have a model with your textfield in it as so:

class MyModel(models.Model):
   template = models.TextField()


and you have a view which renders the template defined in the next
field

def my_view(request):
   m = MyModel.objects.get(pk=1)  # for example the first one

   t = Template(m.template)  #this creates a template from your string
in the model
   c = Context({'form': form, etc.. #any context to go into the
template})

  # now you can just return the rendered template as html
  return HttpResponse(t.render(c))

For more info refer to: 
http://docs.djangoproject.com/en/dev/ref/request-response/

Cheers,

Dan

On Jul 22, 12:49 pm, Ogre  wrote:
> I have a model where I need to be able to insert template tags into a
> TextField in the admin as part of the content and then have them
> rendered properly on the front-end.
>
> Can this be done?  And if so, can someone recommend a method?  I
> understand the security concerns of opening that field up to python.
>
> Thanks in advance.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Pass template tags through TextField?

2009-07-22 Thread Ogre

I have a model where I need to be able to insert template tags into a
TextField in the admin as part of the content and then have them
rendered properly on the front-end.

Can this be done?  And if so, can someone recommend a method?  I
understand the security concerns of opening that field up to python.

Thanks in advance.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---