Thursday, September 1, 2016

Reading an Uploaded File in a Django 1.9 Model

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.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e777f8dd-5acb-4134-9778-385e53c0826a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment