0

I've been spending many hours trying to find a way to upload images in Django.

If you want to upload it to models it's very easy, but as soon as you don't want models it's impossible, which is weird since it's integrated in the models. Any other framework would have a simple integrated solution. I've looked for plugins, same thing, impossible to find one.

Here is the admin view I added:

class ImageUploadForm(forms.Form):
    image = forms.ImageField()

@staff_member_required
def uploadImage(request):
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid() and form.is_multipart():
            return HttpResponse('so now what?')

    context = { 'form': form }
    return render_to_response('blogs/admin/upload.html', context, RequestContext(request))

So my question: Is there an easy way to upload images with Django without using models?

6
  • 2
    have you looked here? docs.djangoproject.com/en/dev/topics/http/file-uploads Commented Feb 19, 2014 at 17:41
  • yes and there is no sign of already made code that allows Image upload. The code they give doesn't look for duplicates. Commented Feb 19, 2014 at 17:46
  • @yuvi : Is there an easy way to upload images with Django without using models? All the frameworks I know do that. Commented Feb 19, 2014 at 17:47
  • 1
    Yes. Use a form like in the link @clime gives you. A form doesn't have to be linked to any model and have almost the exact validation capabilities and features Commented Feb 19, 2014 at 17:48
  • it doesn't check for same names, it just overwrite it. Commented Feb 19, 2014 at 17:53

1 Answer 1

1

I have absolutely no idea why you keep going on about image uploads being tied to models. It isn't, in any way at all: there is no code in the Model class that deals with image uploads. Even the File and Image fields don't have any code dealing with uploads: all they do is call out to the Storage class, which is exactly what you should do.

clime has already given you the link to the file upload docs. As you should be able to see, they explain fully how to upload a file from a form, with absolutely no mention of models at all.

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

1 Comment

I think he's having a problem understaing how to validate that there's no file with the same name.

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.