My view:
@login_required
def list(request):
user = User.objects.get(pk=request.session['user.id'])
# Handle file upload
if request.method == 'POST':
form = dataFileForm(request.POST, request.FILES)
if form.is_valid():
newdat = dataFiles(datafile = request.FILES['datafile'])
newdat.user_id = user
newdat.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('tilda.myapp.views.list'))
else:
form = dataFileForm() # A empty, unbound form'''
# Load documents for the list page
datafiles = dataFiles.objects.all()
# Render list page with the documents and the form
return render_to_response(
'myapp/list.html',
{'datafiles': datafiles, 'form': form, },
context_instance=RequestContext(request)
)
Under Windows7, using Python 2.7.5, with MySQL, this works after login, showing a list of files already uploaded and the form to upload a new file. @login_required
def list(request):
user = User.objects.get(pk=request.session['user.id'])
# Handle file upload
if request.method == 'POST':
form = dataFileForm(request.POST, request.FILES)
if form.is_valid():
newdat = dataFiles(datafile = request.FILES['datafile'])
newdat.user_id = user
newdat.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('tilda.myapp.views.list'))
else:
form = dataFileForm() # A empty, unbound form'''
# Load documents for the list page
datafiles = dataFiles.objects.all()
# Render list page with the documents and the form
return render_to_response(
'myapp/list.html',
{'datafiles': datafiles, 'form': form, },
context_instance=RequestContext(request)
)
Cheers, Nigel
07914 740972
07914 740972
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADeX7vy_DQ7szJTdmKsosyfrAwx5mQgLaspFD%3Dp%2BeYzvK%2Buo_w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment