django 轮播图上传_python-轮播的Django模板/视图问题

博主正在尝试在Django项目中实现首页轮播图的自动显示,当前问题在于图片只有在点击上传按钮后才会出现。目标是使图片在页面加载时即显示。代码包括index.html、carousel.html、views.py和相关模型、表单的定义。博主询问是否可能在不点击上传按钮的情况下让图片自动显示,考虑可能需要使用Ajax来解决。
摘要由CSDN通过智能技术生成

好的,这是交易:

这是我目前正在从事的工作:

看到顶部的两个箭头?那应该是图片轮播的地方.但是,此轮播中没有图片.也就是说,直到我单击“上传”按钮.

因此,我的目标是使图片在我什至没有单击“上传”按钮之前就显示在首页上.

我该如何解决这个问题?

我的代码:

的index.html

{% extends 'webportal/defaults.html' %}

{% block body %}

{% include 'webportal/carousel.html' %}

So far we have been able to establish what the user tables will be have created or are in process of

creating

the ability to create, update, destroy users.

For now this ability is limited to the main user table, however the models will be easily extended

to other

tables as they are needed

Also not a lot of thought has gone into styling yet, we know that the page is suppose to resemble

the parent

organizations page. Right now we have been more focused on getting each individual component

working. Later we

will merge them into a whole.

{% include 'webportal/info_row.html' with one=one two=two three=three %}

{% endblock %}

Carousel.html:

{% load staticfiles %}

{% load filename %}

{% csrf_token %}

{{ form.non_field_errors }}

{{ form.docfile.label_tag }} {{ form.docfile.help_text }}

{{ form.docfile.errors }}

{{ form.docfile }}

Views.py:

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)

)

Models.py:

class Document(models.Model):

docfile = models.ImageField(upload_to='webportal/static/img/')

class DeleteForm(ModelForm):

class Meta:

model=Document

fields=[]

Forms.py:

class DocumentForm(forms.Form):

docfile = forms.ImageField(label='Select a file', help_text='max. 42 megabytes')

如果我想做的事情是不可能的,我不会感到惊讶.如果有办法做到这一点,是否涉及Ajax?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值