如何每次都为结果创建唯一的引用?

时间:2018-07-18 07:55:29

标签: python django

通常,我会在网站上创建一个页面。意思是:一个人进来,加载一个xml文件,选择几个参数,然后输出结果。我没有找到如何立即处理xml文件的方法。因此,我将带有参数的文件上传到数据库,然后将我们重定向到包含结果的页面。一切正常,但是有问题。我还没有弄清楚如何每次都为结果创建一个唯一的链接。现在我有一个结果链接,它只显示最后一个... 上传者的views.py

def upload_file(request):
if request.method == 'POST':
    form = DocumentForm(request.POST, request.FILES)
    if form.is_valid():
        form.save()
        return redirect('lessons:index')
else:
    form = DocumentForm()
return render(request, 'templates/upload/upload.html', {'form': form})
 downloader

处理程序的views.py

def lessons_view(request):

        a = keker()

        return render(request, 'templates/lessons/ocenki.html', {'ocenki': a})

添加处理程序功能

1 个答案:

答案 0 :(得分:0)

尝试这样的代码(python 3.6):

# A class to build the object
class Sentence(object):
    def __init__(self, b, p, s):
        self.book     = b
        self.page     = p
        self.sentence = s

    def getInfo(self):
        return self.book, self.page, self.sentence

# Make a list, and append the book, page and sentence generated from the `Sentence` class
sentenceInfo = []
for b, p, s in zip(bookCodes, pages, sampledSentances):
    sentenceInfo.append(Sentence(b, p, s).getInfo())

print(sentenceInfo)