Jump to content
Sign in to follow this  

Django - Upload de imagem

Recommended Posts


Estou a tentar fazer um upload de imagem em Django, mas não estou a conseguir...

Estou a tentar fazer da seguinte maneira:


class TestUpload(models.Model):
 model_pic = models.ImageField(upload_to='Temp/', blank=True, null=True)


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


def index(request):
if request.method == 'POST':
	form = TestUploadForm(request.POST, request.FILES)
	if form.is_valid():
		return render_to_response('index.html', {'form': form})
	form = TestUploadForm()
return render_to_response('index.html', {'form': form}, context_instance=RequestContext(request)


<!doctype html>

 <title>{% block title %}{% endblock %}</title>
{% block content %}{% endblock %}
<form action="" method="post" enctype="multipart/form-data">{% csrf_token %}
				<input id="id_image" type="file" class="" name="image">
			<input type="submit" value="Submit" id="Save" />

Selecciono a imagem, depois quando carrego no botão "Submit", diz me: 'TestUploadForm' object has no attribute 'save'

Alguém me pode ajudar? Sou novo em Django...


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.