0

Trying to save images to a specific folder in django. I get no error but the file doesn't show up where its supposed to.

Here is the model:

class FileUploadHandler(models.Model):
    title = models.CharField(max_length=100)
    file = models.ImageField(upload_to='/wiki/static/') 

View:

def image_upload(request):
    if request.method == 'POST':
        form = UploadImageForm(request.POST, request.FILES)
        if form.is_valid():
            FileUploadHandler(request.FILES['image'])
            form.save
            return render_to_response('wiki/gallery.html')
    else:
        form = UploadImageForm()
    return render_to_response('wiki/gallery.html', RequestContext(request, {'form': form}))

Totally stumped since I don't get an error.

5
  • What do you have in your settings.py under MEDIA_ROOT and MEDIA_URL? Where is your folder wiki placed? Commented Nov 24, 2014 at 20:42
  • MEDIA_ROOT = '/Python27/Lib/site-packages/django/bin/mideastinfo/wiki/static/' Commented Nov 24, 2014 at 21:24
  • Could it have to do with permissions? Commented Nov 24, 2014 at 21:32
  • That could be eventually an issue. Why don't you upload the within your project? Commented Nov 24, 2014 at 22:02
  • The project is on system python. I didn't use a virtual env. I know better now, but to finish this up, I'm just going to keep it on system install Commented Nov 24, 2014 at 22:34

2 Answers 2

2

don't you need parenthesis at the end of form.save, i.e. form.save()

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that was an oversight, thank you. However, that didn't seem to solve it.
0
FileUploadHandler.objects.create(file=request.FILES['image'])

https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.create https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#handling-uploaded-files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.