1👍
✅
Assuming you have something like a CSVFile model object, you’ll want to pass that object to your template and access the file field’s url property. Something like this:
Assuming something like this in your models.py:
class CSVFile(models.Model):
...
file = models.FileField(...)
You’ll need to lookup the object and pass it to your template in views.py:
def some_view(request, ...):
...
obj = CSVFile.objects.get(...)
return render('path/to/template.html', {'obj': obj})
And then get the url in template.html like so:
...
<div id="CSVTable"></div>
<script>
$(function() {
$('#CSVTable').CSVToTable({{ obj.file.url }});
});
</script>
...
See the documentation on Django FileField for more information.
Source:stackexchange.com