Do you have a model with a fileField?
I think you are wrong passing file to template, if you have a model with filefield you can use media url something like
class Mymodel(Model):
myfile = models.FileField(upload_to="my_file_path_in_media")
so you can use a form
class Myform(forms.ModelForm):
class Meta:
model=Mymodel
fields = '__all__'
so in the view you have
if request.method=='POST':
form = MyForm(request.POST, request.FILE)
if form.is_valid():
instance=form.save()
so you can pass instance in template context
render(request, 'mytemplate.html', {'instance': instance}
in your template you can put a link or whatever you want.
<a href="{{instance.myfile.url}}"> download</a>
take a look https://docs.djangoproject.com/en/1.9/topics/http/file-uploads/ form more info
2016-05-21 10:43 GMT-06:00 Wilfredo Rivera <wrivera51@gmail.com>:
Hello:--
I want to display an uploaded file in the browser. My website save the file in the database, but i don't have idea of how can the website display it once the user click on the link. I am new to django and programming in general so i am learning on a trial and error basis.
The view that handles this is the following:def File_Open(request):
if (request == request.FILES):
file = request.FILES.open()
return render(request, 'recruitment/open_file.html', {file : 'file'})
and the url is this:url(r'^candidatelist/'
r'resume-view/'
r'(?P<resumeFile>/$',
views.File_Open,
name = 'resume_view'
I have search for how can i do this, but haven't found a satisfying answer. Please i will appreciate the 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b2cf38b0-6a6a-45c1-84b9-c4cf678b6c9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
"La utopía sirve para caminar" Fernando Birri

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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAG%2B5VyNDNt-9U3wCuqKzhuu6f61LmRFDt5DzyHvDFYyZUFoCGQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment