I generate a table with django-tables within Django.
I want to create a column with links to txt files in my static directory.
When the user clicks on the link, the txt file should be displayed.
To create a link to the txt file within an html, I simply do:
<a href="{% static co.log %}">txtfile</a>
However, I have problems finding the right way to do this using django-tables.
I tried to define the link column as follows:
logfiles = tables.LinkColumn('{static', text='txtfile', args=[A('log')], orderable=False, empty_values=())
This gives the error
"Reverse for '{static' not found. '{static' is not a valid view function or pattern name."
I also tried this:
tables.py
logfiles = tables.LinkColumn('logfile', text='bla', orderable=False, empty_values=())
urls.py:
url(r'^logfile/', views.logfile, name='logfile')
views.py:
def logfile(request):
return HttpResponse('<p>yeah</p>')
So I can find a way to open a new url, but how to open a specific static file, i.e.how to pass the info from [A('log')], which is basically the filename?
Any help is appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…