[Answer]-Django Python Output

1👍

From the django documentation (which goes into much more detail on the topic of models)

class Poll(models.Model):
    title = models.CharField(max_length=128)

    def __unicode__(self):
        return self.title

If you want to display the content of the poll, you might want to have a method like as_table or something in your model that returns the appropriate HTML (or even better, uses a template tag to render a partial template.)

Assuming you defined as_table and have a poll context variable in your template, you could then render the poll content by using {{poll.as_table}}.

For more details on templates: https://docs.djangoproject.com/en/1.5/topics/templates/

The __unicode__ method shouldn’t be used to perform complex rendering, and is mostly used to be helpful in the generated admin pages.

👤alxbl

0👍

The last part of your code looks ok, but it is mixing TABS and SPACES at the beginning of the line. You should make that all spaces (it is now (taken from the source you cut and pasted and with TAB replaced with ^ and SPACE with %

^%%%%def __unicode__(self):
^%%%%^return self.choice_text

You should replace the character directly before return self.choice_text in your code with 4 spaces.

The easiest way to get rid of those is by using

python -m reindent your_file_name.py
👤Anthon

0👍

You must re indent the file

to Avoid this mistake

http://www.python.org/dev/peps/pep-0008/#indentation

and know Well about python indentation

and i recommend sublime editor ( http://www.sublimetext.com/ ) with Djaneiro (Github) for proper auto suggestions

Leave a comment