def upload_file(request, step_id):
def handle_uploaded_file (file):
current_step = Step.objects.get(pk=step_id)
current_project = Project.objects.get(pk=current_step.project.pk)
path = "%s/upload/file/%s/%s" % (settings.MEDIA_ROOT, current_project.project_no, current_step.name)
if not os.path.exists (path):
os.makedirs(path)
fd = open(path)
for chunk in file.chunks():
fd.write(chunk)
fd.close()
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['file'])
return HttpResponseRedirect('/success/url/')
else:
form = UploadFileForm()
return render_to_response('projects/upload_file.html', {
'step_id': step_id,
'form': form,
})
views:
47answers:
1
+1
A:
Make sure path
has the necessary permissions. The user running the python/django process needs to have write
permissions. chmod
the path to 0777
- this isn't a good mode for production, but it will quickly verify if filesystem permissions are the root of the problem.
Matt
2010-04-25 06:11:32
thanks, how could i chmod the path?
Semanty
2010-04-25 06:13:22
Assuming you have shell access, run `chmod -R 0777 path/to/uploads`
Matt
2010-04-25 06:14:10
sorry, i really don't konw much about chmod and how to use shell to run chmod.
Semanty
2010-04-25 06:23:05
I mean, could the cod be directly modified, and then i can study more deeply
Semanty
2010-04-25 06:29:23
i am using django under windows
Semanty
2010-04-25 06:42:52