我想以Django应用程序前端的形式显示服务器上MEDIA_ROOT中的文件列表。
以下是我要完成的工作:
我的实际代码如下。我只显示受此问题影响的类,函数和文件。在问题的结尾,如果缺少某些内容,您将找到指向整个项目的链接。
views.py(我有两个功能,因为我尝试了两种方法)
class SelectPredFileView(TemplateView):
"""
This view is used to select a file from the list of files in the server.
"""
model = FileModel
fields = ['file']
template_name = 'select_file_predictions.html'
success_url = '/predict_success/'
files = os.listdir(settings.MEDIA_ROOT)
def my_view(request):
my_objects = get_list_or_404(FileModel, published=True)
return my_objects
# TODO: file list not displayed in the HTML, fix
def getfilelist(self, request):
filepa