Read Text file in django

31 views
Skip to first unread message

Lansana Sangare

unread,
May 26, 2020, 4:32:46 PM5/26/20
to Django users
Good evening people,
i'm a beginner at django, i try to read a text file in django template but i only get the data.txt in template. how can i open and read the content of the text file in templates. Below you can see the html section and the output. Thanks in advance

Django model:
class Patienten(models.Model):
Name = models.CharField(max_length=50)
Vorname = models.CharField(max_length=50, null=True)
Geburtsdatum = models.DateField(max_length=10)
Strasse = models.CharField(max_length=100)
Ort = models.CharField(max_length=100, null=True)
Datum = models.DateField(max_length=10, null=True)
Versicherungsnummer = models.CharField(max_length=50)
Letzte_Diagnose = models.CharField(max_length=500)
Schrittinfos = models.FileField(max_length=100, null=True)


html part:
<a class="btn btn-default" href="{% url 'getAllPatienten' %}">Patientendaten<span class="glyphicon glyphicon-pencil"></span></a>
<h2>{% for post in posts%}</h2>
<h1>Patient:{{ post.Name }}</h1>
<p>Geburtsdatum:{{ post.Geburtsdatum|linebreaksbr }}</p>
<p>Versicherungsnummer:{{ post.Versicherungsnummer }}</p>
<p>Letzte Diagnose:{{ post.Letzte_Diagnose }}</p>
<p>Ort:{{ post.Ort }}</p>
<p>Datum:{{ post.Datum }}</p>
<p>Schrittinfos:{{ post.Schrittinfos }}</p>

html Output Part in Templates :

Patient:Sangare

Geburtsdatum:1990-05-30

Versicherungsnummer:D0469556541990

Letzte Diagnose:Gelenkschmerzen

Ort:Essen

Datum:May 26, 2020

Schrittinfos:data.txt


Ammar M. Adam

unread,
May 26, 2020, 5:44:13 PM5/26/20
to django...@googlegroups.com

The FileField Must have a function for that
Use help(django.models.FileField)
It must have some sort of FileField.read() or something like that.
Am also a beginner but I think this should work with you 😉.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/073bceca-3b93-4eb4-9647-873b7a7aa0fe%40googlegroups.com.

Lansana Sangare

unread,
May 27, 2020, 4:30:52 PM5/27/20
to django...@googlegroups.com
Thanks guy, it works now

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHs1H7utBp5rC9av1JM-qAgpRFe7mxiCx%3DS8KUWPJ05DGOHe%3Dw%40mail.gmail.com.

Ammar M. Adam

unread,
May 27, 2020, 5:07:55 PM5/27/20
to django...@googlegroups.com

Welcome 😊 anytime 😁

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
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.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF4Pwrs4Ax8d9P-b%2B8PWdeNNU8R2KLh4x%3D94OQVWpn2MUALYLw%40mail.gmail.com.

Mujahid Abbas

unread,
May 27, 2020, 6:19:24 PM5/27/20
to django...@googlegroups.com
Well

Welcome 😊 anytime 😁

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHs1H7v_zV03DTA8Sd5LomUKnChBeG0yaj89uT%3DtXYsrBVJysQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages