How to access static files in views.py

140 views
Skip to first unread message

Guy NANA

unread,
Dec 25, 2019, 7:32:04 AM12/25/19
to Django users
I want to access static files in views.py but it doesn't work when I use {% load static %} and {% static relative_path %} in the same way like in a template.
Capture d’écran de 2019-12-25 13-31-21.png

Integr@te System

unread,
Dec 25, 2019, 8:20:06 AM12/25/19
to django...@googlegroups.com

On Wed, Dec 25, 2019, 19:32 Guy NANA <guyrost...@gmail.com> wrote:
I want to access static files in views.py but it doesn't work when I use {% load static %} and {% static relative_path %} in the same way like in a template.

--
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/8b8d6254-f0f4-4e2f-8b4d-1c4bde5dc050%40googlegroups.com.

Damby Green

unread,
Dec 26, 2019, 8:05:15 AM12/26/19
to django...@googlegroups.com
hi Guy,
What's the structure of your project and the content of your settings.py?


Le mer. 25 déc. 2019 à 12:32, Guy NANA <guyrost...@gmail.com> a écrit :
I want to access static files in views.py but it doesn't work when I use {% load static %} and {% static relative_path %} in the same way like in a template.

--

Andréas Kühne

unread,
Dec 26, 2019, 8:52:45 AM12/26/19
to django...@googlegroups.com
You can't use the same tags for loading the staticfiles and the static method. However you should be able to load the file via:

But the next question is what is it you want to achieve? Why do you need to load the static file in the view itself?

Regards,

Andréas


Den ons 25 dec. 2019 kl 13:32 skrev Guy NANA <guyrost...@gmail.com>:
I want to access static files in views.py but it doesn't work when I use {% load static %} and {% static relative_path %} in the same way like in a template.

--

Guy NANA

unread,
Dec 26, 2019, 4:27:41 PM12/26/19
to Django users

Capture d’écran de 2019-12-26 22-24-29.png

Here is the screenshot of my application. I want to read the content of my timeseries dataset file 'daily-min-temperatures.csv' in my views.py for future treatements.


Le jeudi 26 décembre 2019 14:05:15 UTC+1, Damby Green a écrit :
hi Guy,
What's the structure of your project and the content of your settings.py?


Le mer. 25 déc. 2019 à 12:32, Guy NANA <guyros...@gmail.com> a écrit :
I want to access static files in views.py but it doesn't work when I use {% load static %} and {% static relative_path %} in the same way like in a template.

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

Gil Obradors

unread,
Dec 27, 2019, 1:27:27 AM12/27/19
to django...@googlegroups.com
Hi!

Like os file system

El dj., 26 de des. 2019, 22:28, Guy NANA <guyrost...@gmail.com> va escriure:
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/d763222b-438b-49dc-8d98-5099913e89d2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages