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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
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.