Reading an Uploaded File in a Django 1.9 Model

12 views
Skip to first unread message

Lior Kofman

unread,
Sep 1, 2016, 11:19:42 AM9/1/16
to Django users
I am very new to Django, but have been using Python since the beginning of the year. I am having trouble opening and reading a text file, and when I use the shell to see what is going on, it prints:

<_io.TextIOWrapper name='edt.txt' mode='r' encoding='UTF-8'>


Here is my code:


from __future__ import unicode_literals


from django.db import models


from django.core.files import File


class Medphysics(models.Model):

    with open('edt.txt', mode = 'r') as infile:

        data = infile.read()

        print(data)


Any feedback would be much appreciated.

Reply all
Reply to author
Forward
0 new messages