Thursday, January 30, 2014

Re: render .txt file in django template

Sort of wrong. Django static files are available as http resources, not available to the template renderer. With django staticfiles you can't do {{file_i_want}}.

If you want to work purely in the template, you have 2 options:
1. Load the txt file url with ajax and put it where you want on the page
2. {% ssi %} if you have the absolute path to the txt file

On Thursday, January 30, 2014 3:57:41 PM UTC-6, Fatih Tiryakioglu wrote:
But the document says that static media isn't about django, but apache (for production). Loading static file contents in the view.py seems to me not effecient.

I am now on development phase, and I think I should render static files in the template now. And in the production phase, I would change just the shortcuts..

Am I wrong?


--


30 Ocak 2014 Perşembe 23:33:11 UTC+2 tarihinde C. Kirby yazdı:
The template engine doesn't have direct access to the filesystem. You will have to pass the file contents from your view to the template:

1.Load the file in your view
2. Read it into a context variable.
3. Render the context variable in your template

On Thursday, January 30, 2014 3:29:29 PM UTC-6, Fatih Tiryakioglu wrote:
Hi all,

Could you please show me how can I render .txt static files (they are user comments) in django template? I couldn't resolve that issue for a month..

I appreciate your help.


--

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ec22d77f-0681-4f95-ae02-16ea9ac734b5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment