我正在创建文件共享应用。我可以上传文件,但无法向用户提供下载链接。
请查看以下视图,
def user_in(request):
if not request.user.is_authenticated:
return render(request, 'accounts/logout.html')
else:
if request.method == 'POST':
form_new = Fileupload(request.POST, request.FILES )
#instance=form_new.save(commit=False)
#instance.save()
if form_new.is_valid():
instance = form_new.save(commit=False)
instance.user_uploaded=request.user
instance.save()
return redirect('in')
else:
form_new = Fileupload()
data = user_files.objects.filter(user_uploaded=request.user)
args = {'form_new': form_new, 'data': data}#, 'url': form_new.get_absolute_url()}
return render(request, 'accounts/in.html', args)
和model.py是,
class user_files(models.Model):
Filename = models.CharField(max_length=50)
Browse = models.FileField(upload_to='img/')
user_uploaded = models.CharField(max_length=50, blank=True)
模板是,
<form action="." method="POST" enctype="multipart/form-data" >
<h3>Welcome to DropBox<br><br></h3>
{% csrf_token %}
{{form_new.as_p}}
<p><input type="submit" value="Save" ></p>
<br>
<a href="{% url 'logout' %}">Logout</a>
{%else%}
<p>You must login first</p>
<a href="{% url 'login' %}">Logout</a>
{% endif %}
<br><br>
S
<a href="{% url 'share' %}">Share Files</a>
<br><br>
User is : {{request.user}}
{% for da in data %}
<h3>{{da.Filename}} {{da.Browse}} </h3>
{% endfor %}
</form>
请你指导我如何为上传的链接提供下载链接,我现在卡住了。
提前感谢。