0

here is the output from $python manage.py shell

>>> a=Mocument.objects.all()
>>> a
[<Mocument: abc.xlsx>, <Mocument: 1.csv>, <Mocument: ok.csv>, <Mocument: 11.csv>, <Mocument: 12.csv>]
>>> a[0]
<Mocument: abc.xlsx>
>>> for i in a:
...     print i
... 

here is the output

abc.xlsx
1.csv
ok.csv
11.csv
12.csv

till here all great. problem starts when i try to retrieve data in HTML template. here is my html file code

<html>
    <head>
        <meta charset="utf-8">
        <title>Minimal Django File Upload Example</title>   
    </head>

    <body>
        <!-- List of uploaded documents -->
        {% a=Mocument.objects.all() %}      
        {% for i in a %}
            <p>{% print i %}</p>    
        {% endfor %}

    </body>         
</html> 

here is the Error details

Error:-------------------- Exception Value: Invalid block tag: 'a=Mocument.objects.all()'

please help.

ashir nasir
  • 207
  • 2
  • 6
  • 11

1 Answers1

2

You are not writing valid django template code. You cannot use any python code in templates. You have to use specific django tags and filters. Have a read here: https://docs.djangoproject.com/en/1.5/topics/templates/

I your case, you should do this:

{% for i in mocument_objects %}
    <p>{{ i }}</p>    
{% endfor %}

You would need to pass monument_objects into your template context from the view.

jproffitt
  • 6,225
  • 30
  • 42
  • you right, i did the same as it is in this post http://stackoverflow.com/questions/5871730/need-a-minimal-django-file-upload-example/8542030#8542030. its doing everything except its not printing the file names. even the BULLETS are printed but filename is missing/blank – ashir nasir Sep 23 '13 at 00:46
  • Did you override the `__unicode__` method on the `Mocument` model? – jproffitt Sep 23 '13 at 00:52
  • there are two class in model.py and i have added def __unicode__(self): return self.mocfile . is it ok? – ashir nasir Sep 23 '13 at 00:59
  • @ashirnasir maybe you are using `{% print i %}` instead of `{{ i }}`. That's probably why you are not getting the filenames. I suggest you read the django docs about [The Django template language](https://docs.djangoproject.com/en/1.4/ref/templates/api/). – juliomalegria Sep 23 '13 at 01:06