Django template/view issues with carousel

前端 未结 1 1263
面向向阳花
面向向阳花 2021-01-15 20:37

OK, so here\'s the deal:

This is currently what I\'m working on:

\"Enter

相关标签:
1条回答
  • 2021-01-15 21:25

    The .py files are Python code. In Python, leading whitespace matters.

    In Views.py, the carousel function does not contain valid Python code:

    def carousel(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()
    
                # Redirect to the document list after POST
                return HttpResponseRedirect('http://127.0.0.1:8000/alzheimers/')
    else:
    
     form = DocumentForm() # A empty, unbound form
    # Load documents for the list page
    documents = Document.objects.all()
    #documents=DocumentForm().
    # Render list page with the documents and the form
    return render_to_response(
        'webportal/index.html',
        {'documents': documents, 'form': form,},
        context_instance=RequestContext(request)
    )
    

    Instead, it should probably be:

    def carousel(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()
    
                # Redirect to the document list after POST
                return HttpResponseRedirect('http://127.0.0.1:8000/alzheimers/')
    
        else:
    
            form = DocumentForm() # A empty, unbound form
            # Load documents for the list page
            documents = Document.objects.all()
            #documents=DocumentForm().
            # Render list page with the documents and the form
            return render_to_response(
                'webportal/index.html',
                {'documents': documents, 'form': form,},
                context_instance=RequestContext(request)
            )
    

    But it is not clear if the else part belongs to the first or the second if construct.

    0 讨论(0)
提交回复
热议问题