我使用Django在Heroku上部署了一个应用程序,到目前为止它似乎正在工作但我在上传新缩略图时遇到问题.我已经安装了Pillow,允许我在上传图像时调整图像大小并保存调整大小的缩略图,而不是原始图像.但是,每次上传时,都会出现以下错误:"此后端不支持绝对路径." 当我重新加载页面时,新图像就在那里,但它没有调整大小.我正在使用Amazon AWS来存储图像.
我怀疑它与我的models.py有关.这是我的调整大小代码:
class Projects(models.Model):
project_thumbnail = models.FileField(upload_to=get_upload_file_name, null=True, blank=True)
def __unicode__(self):
return self.project_name
def save(self):
if not self.id and not self.project_description:
return
super(Projects, self).save()
if self.project_thumbnail:
image = Image.open(self.project_thumbnail)
(width, height) = image.size
image.thumbnail((200,200), Image.ANTIALIAS)
image.save(self.project_thumbnail.path)
Run Code Online (Sandbox Code Playgroud)
有什么东西我不见了吗?我需要告诉别的吗?
我有一个Javascript函数,它给我一天工作的总时数为HH:MM.我想将这些数字转换为小数,以便我可以添加它们.我此刻似乎遇到了错误:
function timeToDecimal(t) {
t = t.split(':');
return = t[0]*1 + '.' parseInt(t[1])/60;
}
Run Code Online (Sandbox Code Playgroud)
我错过了重要的事吗?我只是不断收到语法错误.
我的 Django 项目有一个“标签”字段,用户可以在其中为他们的帖子添加标签。目前这存储在我的模型中的 models.CharField(max_length=200) 字段中。
我想要做的是让它在显示帖子时,每个单词都打印有自己的 URL,以便按特定标签对帖子进行排序。例如,每个帖子还有一个“类别”models.CharField,他们可以在其中从下拉列表中选择一个类别,该类别在帖子中成为一个 URL。
例如在我的 Views.py 中:
@login_required
def category(request, category):
thisuser = request.user
if request.method == "POST":
category = request.POST['category']
else:
category = ''
following = Follow.objects.filter(follower=thisuser).order_by('-pubdate')
followers = Follow.objects.filter(who_following=thisuser).order_by('-pubdate')
posts = Post.objects.filter(category__contains=category)
args = {'posts': posts, 'thisuser': thisuser, 'following': following, 'followers': followers}
args.update(csrf(request))
args['category'] = category
return render_to_response('lobby.html', args)
Run Code Online (Sandbox Code Playgroud)
在我的模板中:
<a href="/lobby/posts/category/{{post.category|lower}}/">Category: {{post.category}}</a>
Run Code Online (Sandbox Code Playgroud)
是否有一个 {% for %} 模板标签,我可以用逗号分割标签字段中的值,然后将它们作为自己的实例呈现?或者我是否需要做其他事情,比如为标签创建一个关系数据库(因为一个帖子可以有多个标签),然后通过帖子 ID 迭代它们?