Python Django模板/使用旋转木马查看问题

Python Django模板/使用旋转木马查看问题,python,django,twitter-bootstrap,django-models,carousel,Python,Django,Twitter Bootstrap,Django Models,Carousel,好的,下面是交易: 这就是我目前正在做的工作: 看到顶部的两个箭头了吗?这就是图片传送带应该放在的地方。但是,此旋转木马中没有图片。也就是说,直到我点击“上传”按钮 所以,我的目标是在我点击“上传”按钮之前让图片出现在第一页 我如何解决这个问题 我的代码: Index.html Models.py: Forms.py: 如果我想做的是不可能的,我不会感到惊讶。如果有办法做到这一点,它是否涉及Ajax?这些.py文件都是Python代码 在Views.py中,carousel函数不包含有效的P

好的,下面是交易:

这就是我目前正在做的工作:

看到顶部的两个箭头了吗?这就是图片传送带应该放在的地方。但是,此旋转木马中没有图片。也就是说,直到我点击“上传”按钮

所以,我的目标是在我点击“上传”按钮之前让图片出现在第一页

我如何解决这个问题

我的代码:

Index.html Models.py: Forms.py:
如果我想做的是不可能的,我不会感到惊讶。如果有办法做到这一点,它是否涉及Ajax?

这些.py文件都是Python代码

在Views.py中,
carousel
函数不包含有效的Python代码:

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)
)
相反,它可能应该是:

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)
        )

但尚不清楚
else
部分属于第一个
if
构造还是第二个
构造。

听起来您希望图片从未来传回,并在上传之前显示出来。…:-)我可能误解了一些东西,就像你引导程序上的注释一样
.container>.row>.col-md-12>p
可以更简单地重写为
.container>p
(通常不需要添加带全宽列的行,并且会添加许多不必要的标记)。我上传的图片存储在服务器上,因此我看不出它们将来必须如何传播@也许我是个白痴,把上传代码搞砸了。“我们拭目以待。”他们适时地提到了这件事bootstrap@thebjorn您可能是指
.container p
,因为
.container>.row>.col-md-12>p
.container>p
是不等价的,这是固定的@彼得阿贾克斯能帮我吗?
from django.shortcuts import render
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth import authenticate, login
from webportal.views.authentication import LoginForm
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.conf import settings
from webportal.forms.forms import DocumentForm
from webportal.models import Document, DeleteForm
is_server = True
def delete(request, my_id):
    Deleted=get_object_or_404(Document, docfile=my_id)
    if request.method=='POST':
        form=DeleteForm(request.POST, instance=Deleted)
        if form.is_valid():
            Deleted.delete()
            return HttpResponseRedirect('http://127.0.0.1:8000/alzheimers/')
    else:
        form=DeleteForm(instance=Deleted)
    return render_to_response(
        'webportal/index.html',
        {'documents': documents, 'form': form,},
        context_instance=RequestContext(request)
    )

# Redirect to the document list after POST
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)
)
class Document(models.Model):
    docfile = models.ImageField(upload_to='webportal/static/img/')
class DeleteForm(ModelForm):
    class Meta:
        model=Document
        fields=[]
class DocumentForm(forms.Form):
    docfile = forms.ImageField(label='Select a file', help_text='max. 42 megabytes')
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)
)
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)
        )