所以我有5个图像作为静态文件,我想随机选择一个图像来显示当我按下一个按钮。我在获取imagename更新时遇到了问题。当我将名称硬编码到html中时,它确实有效。
我认为:
def test(request):
imagename = 'img' + str(random.randint(0,5)) + '.jpeg' #all the images end with jpeg so this can't be the problem
print(imagename)
return render(request, 'mai
views.py:
def index(request):
return render_to_response('index.html', {})
def photos(request, artist):
if not artist:
return render_to_response('photos.html', {'error' : 'no artist supplied'})
photos = get_photos_for_artist(artist)
if not phot
我遵循了一个教程,并使用下面这行代码获得了一个TypeError:
c.update(csrf(request))
这是全景图
from django.shortcuts import render
from django.views.decorators import csrf
def index(request):
c = {} #dictionary called c
c.update(csrf(request))
return render(request, 'login/index.html', c)
我是在做一些已经改变的东西的旧版本吗?我
我使用Django和Postgresql作为数据库。我有一个包含两个字段name和item的HTML页面。我可以通过单击submit将数据保存在数据库中。但是,我想在HTML页面中显示从数据库中保存的数据。这意味着,每当我们加载页面时,它都应该显示已保存的数据,并且在提交新数据之后,应该更新列表。下面是我的python代码。
models.py
from django.contrib.auth.models import User
from django.db import models
class AllocationPlan(models.Model):
name = mode
基本上,在我的index.html模板中,我希望在相同的(两者都有csrf)上有登录和注册表单。这是我的看法。
def index(request):
c = {}
c.update(csrf(request))
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('
嗨,我正在为一个项目学习Django,我正在尝试上传一个文件,并通过使用POST的表单在下拉列表中添加一个on选项。这是我的档案:
views.py
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
from .forms import UploadFileForm
# function to handle an uploaded file.
from save_uploaded_file import handl