DJANGO奇怪的行为一旦尝试保存文件

时间:2013-09-26 15:23:16

标签: python django

out put是一个HTML文件,允许用户上传CSV文件并将其转换为excel。 这两个文件都会在用户点击上传时显示在页面上。

发生这种情况很奇怪,有时用户可以在同一页面上下载文件,如果他点击该文件或者保存,但有时候没有。

我尝试使用SYNCDB和rrstart,但问题仍然存在。

这里是views.py

def list(request):
    # Handle file upload

    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()
        docfile = request.FILES['docfile']       

        path, xfilename = os.path.split(docfile.name)
        xfilename = os.path.splitext(xfilename)[0]
        xnewfilename = 'Modified_%s.xlsx' % xfilename
        newfilename = os.path.join(path, xnewfilename)
        wwdoc = Document(docfile = newfilename)
            wwdoc.save()

        workbook = xlsxwriter.Workbook('/home/koin/Documents/myproject/myproject/myproject/media/documents/'+newfilename)

..........某些数据库插入并更新了sqlite db中的记录........

        worksheet = workbook.add_worksheet("Emp")
        worksheet2 = workbook.add_worksheet("Manager")
        worksheet3 = workbook.add_worksheet("Clerk")

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('myproject.myapp.views.list'))
    else:
        form = DocumentForm() # A empty, unbound form

     documents = Document.objects.all()
    return render_to_response(
        'myapp/list.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request)l
    )

使用sqlite3。请指出错误。

list.html

{% for document in documents %}
                <li><a href="{{ document.docfile.url }}">{{ document.docfile.name }}</a></li>
{% endfor %}

项目/ urls.py

urlpatterns = patterns('',
    (r'^myapp/', include('myproject.myapp.urls')),
    (r'^$', RedirectView.as_view(url='/myapp/list/')), # Just for ease of use.
    (r'', 'myproject.myapp.views.list'),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我发现这条线特定阻止用户下载文件

(r'', 'myproject.myapp.views.list'),

我如何为csv和xlsx文件添加例外?

0 个答案:

没有答案