On Jul 15, 9:14 am, luca72 <lucabe...@libero.it> wrote: > Hello and thanks for your help. > I think that i need context, i attach my test file: > > from django.shortcuts import render_to_response > from off_bert.offerte.forms import RichiestaForm > from django.http import HttpResponseRedirect > > def richiesta(request): > if request.method == 'POST': > form = RichiestaForm(request.POST) > if form.is_valid(): > processo_richiesta() > else : > form = RichiestaForm() > return render_to_response('richiedi.html',{'form': form}) > > def processo_richiesta(): > from django.template import Template, Context > t = Template('ciao, {{scritto}}') > c = Context({"scritto": """script type="text/javascript"> > alert("ok")</ > script>"""}) > > t.render(c) > > But don't work > > can you tell me some sample to look > > Thanks > > Luca >
Again, "doesn't work" isn't a very useful thing to say - it would be more helpful to describe what actually happens. However, there are a couple of things wrong with the code you have posted. Firstly, when you call processo_richiesta(), you don't actually do anything with the rendered template. I think you mean 'return processo_richiesta()', which will return the rendered template as the response so that it is displayed. Secondly, auto-escaping will mean that your script tags will not work. You'll need to either use "mark_safe" in your context definition, or the "safe" filter in your template. See here for more information: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#filters-and-auto-escaping Thirdly, the final line of your view needs to be one indent to the left, so that it is caught in the case that the form is posted but not valid. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---