Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!


Django: Passar dados das views para o template

Recommended Posts



Pessoal, estou a aprender Django, mas estou com problemas ao passar dados das views para os templates.

A minha view tem este código:

def about_view(request):
   desc = 'This is a message from views'
   data = {'desc': desc}
   return render_to_response('home/about.html', data, 'context_instance=RequestContext(request)')

E no template estou a receber os dados desta forma:

<h4>{{ desc }}</h4>

Erro: http://dpaste.com/942165/

Request URL: http://localhost:8000/about/

Django Version: 1.4.3

Exception Type: AttributeError

Exception Value: 'str' object has no attribute 'update'

Exception Location: /usr/local/lib/python2.7/dist-packages/django/template/loader.py in render_to_string, line 174

Python Executable: /usr/bin/python

Python Version: 2.7.1

Alguém me consegue ajudar?

É que não estou a conseguir fazer debbugging disto...

Edited by thoga31

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.