how to load and render "static .txt file content" from django template

2,284 views
Skip to first unread message

Fatih Tiryakioglu

unread,
Dec 7, 2013, 7:16:09 AM12/7/13
to django...@googlegroups.com
Hi all,

I want to render a static .txt file from django template, but I can't load it. I tried some combinations. Here is some of them:

       <textarea src="shortcut/to/text-file.txt" />

       <textarea src="shortcut/to/text-file.txt"> </textarea>

       <textarea> src="shortcut/to/text-file.txt" </textarea>

How can I load the context of this file?

Thanks all.

Note: I can render static image files, so it is not a settings problem.


Tom Lockhart

unread,
Dec 7, 2013, 1:13:39 PM12/7/13
to django...@googlegroups.com
On 2013-12-07, at 4:16 AM, Fatih Tiryakioglu <fati...@gmail.com> wrote:

Hi all,

I want to render a static .txt file from django template, but I can't load it. I tried some combinations. Here is some of them:

       <textarea src="shortcut/to/text-file.txt" />

       <textarea src="shortcut/to/text-file.txt"> </textarea>

       <textarea> src="shortcut/to/text-file.txt" </textarea>

How can I load the context of this file?

Not sure about the textarea markup, but I would think that you would need to load the static tag and do something like

<textarea src="{% static "shortcut/to/text-file.txt" %}"/>

Take a look at the html your browser is getting and see if the paths for your text files look similar to the paths already working for images.

hth

                  - Tom



Thanks all.

Note: I can render static image files, so it is not a settings problem.



--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b54669cb-6d8e-481a-a4f7-665fd1e0876d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tom Lockhart


François Schiettecatte

unread,
Dec 7, 2013, 2:14:10 PM12/7/13
to django...@googlegroups.com
You might also want to make the textarea readonly otherwise users will be able to modify the text which may not be what you want.

You can also use {% include ... %} to include a static file, I do that for help pages.

François
> <T_Lockhart_791_email_sig.png>
>
>
> --
> 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 post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/FE709582-B7A6-4575-A12A-2CD35A235853%40gmail.com.
signature.asc
Reply all
Reply to author
Forward
0 new messages