Python 当AmazonS3私有上传/下载在我的django视图中工作时,我如何让它们在管理中工作?
我试图通过amazon private s3获得上传和下载,但无法获得完整的循环。我已经非常接近了,但它有一个有趣的行为,如下所述 什么有效Python 当AmazonS3私有上传/下载在我的django视图中工作时,我如何让它们在管理中工作?,python,django,amazon-web-services,amazon-s3,django-forms,Python,Django,Amazon Web Services,Amazon S3,Django Forms,我试图通过amazon private s3获得上传和下载,但无法获得完整的循环。我已经非常接近了,但它有一个有趣的行为,如下所述 什么有效 从管理员上传 从管理员处下载 使用“我的团队”视图从我的模板下载 什么不起作用 从我创建的视图+模板上传不会改变数据库 奇怪的是,上传的行为就像表单是有效的一样,甚至当你在管理面板中查看时,就好像上传是在没有任何更改的情况下发生的一样 **版本** Django版本1.9.7 我的相关观点 def my_team(request, challeng
- 从管理员上传
- 从管理员处下载
- 使用“我的团队”视图从我的模板下载
- 从我创建的视图+模板上传不会改变数据库
- 奇怪的是,上传的行为就像表单是有效的一样,甚至当你在管理面板中查看时,就好像上传是在没有任何更改的情况下发生的一样
def my_team(request, challenge):
"""A page showing details of a teams in a challenge."""
# Find the team that this user belongs to...
team = Team.objects.filter(challenge=challenge, members__id=request.user.id).first()
# Boot them out if they are not in any team.
if not team:
return redirect('challenges_list')
special_form = SpecialForm(instance=team)
upload_complete = False
# POST
if request.method == 'POST':
special_form = SpecialForm(request.POST or None, request.FILES, instance=team)
if special_form.is_valid():
special_form.save()
upload_complete = True
# this template us also used in team-details
return render(request, 'challenges/team_details.html', {
'challenge': challenge,
'upload_form': special_form,
'team': team,
'special_form': special_form,
'upload_complete': upload_complete
})
我的相关车型
special_storage = storages.backends.s3boto.S3BotoStorage(
acl='private',
querystring_auth=True,
querystring_expire=300,
)
class Team(TimeStampedModel):
challenge = models.ForeignKey(Challenge, on_delete=models.CASCADE, related_name='challenge_teams')
application = models.OneToOneField(ChallengeApplication, on_delete=models.CASCADE, related_name='challenge_team', null=True, blank=True)
members = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True)
name = models.CharField(max_length=100)
company_name = models.CharField(max_length=100, blank=True)
description = models.TextField(blank=True)
special_item = models.FileField(
null=True,
blank=True,
help_text='File here...',
storage=special_storage,
)
我的相关表格
class SpecialForm(forms.ModelForm):
class Meta:
model = Team
fields = ('special_item',)
我的相关模板
<form action="#" method="post">
{% csrf_token %}
{{ special_item_form }}
<input type="submit" value="Submit" />
</form>
{%csrf_令牌%}
{{特殊项目形式}
您应该将enctype=“multipart/form data”
属性添加到您的
标记中。没有它,请求。文件
将为空