Links to files

20 views
Skip to first unread message

Karl Ritchie

unread,
Jan 5, 2018, 12:00:11 PM1/5/18
to Django users
Hi I'm very new to Django. I tried searching for this but the answers I found aren't very clear. I'm wanting to create links to PDF documents.  I've created an app called writing with a static folder with PDF files. At first I just put an html  link in the template file but it when I ran it it said it couldn't find the file.
I think I have to change the View.py and URL.py in Writing but what do I change it to and what do I put in the template file for the link?


Matemática A3K

unread,
Jan 6, 2018, 2:24:58 AM1/6/18
to django...@googlegroups.com
On Fri, Jan 5, 2018 at 1:50 PM, Karl Ritchie <karlr...@gmail.com> wrote:
Hi I'm very new to Django. I tried searching for this but the answers I found aren't very clear. I'm wanting to create links to PDF documents.  I've created an app called writing with a static folder with PDF files. At first I just put an html  link in the template file but it when I ran it it said it couldn't find the file.
I think I have to change the View.py and URL.py in Writing but what do I change it to and what do I put in the template file for the link?


Karl,

"A static file is a static file", it doesn't matter if it is a jpg or a pdf. You should read https://docs.djangoproject.com/en/2.0/howto/static-files/ and think that instead of img tags for jpgs you will use a tags for pdfs

HTH!
 

--
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...@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/dcd1a1fc-3aac-4562-a8c3-159b846a44c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jani Tiainen

unread,
Jan 6, 2018, 6:20:25 AM1/6/18
to django...@googlegroups.com
If those files are really static you don't need Django to serve them (maybe on development phase). You shouldn't put those files in static files if files are not really static (created before your app is ever launched). If you create files on the fly, you probably better to serve them as a media files ("user uploaded files") and just hookup your front end webserver to serve those files.

There is a very short section in Django docs which tries to explain how MEDIA_URL and MEDIA_ROOT works (similar as STATIC_URL and STATIC_ROOT but for different purpose)


On Fri, Jan 5, 2018 at 6:50 PM, Karl Ritchie <karlr...@gmail.com> wrote:
Hi I'm very new to Django. I tried searching for this but the answers I found aren't very clear. I'm wanting to create links to PDF documents.  I've created an app called writing with a static folder with PDF files. At first I just put an html  link in the template file but it when I ran it it said it couldn't find the file.
I think I have to change the View.py and URL.py in Writing but what do I change it to and what do I put in the template file for the link?


--
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...@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/dcd1a1fc-3aac-4562-a8c3-159b846a44c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...
Reply all
Reply to author
Forward
0 new messages