I'm trying to make a simple app: I've done the Django Girls tutorial and now I'm trying to use it as well including an image using the < a href="http://cloudinary.com/"> Cloudinary
But I'm having the following error:
Theerroroccursatlineupload_result=cloudinary.uploader.upload(file)
offileviews.py
Followcode
models.py
fromdjango.dbimportmodelsfromdjango.utilsimporttimezonefromcloudinary.modelsimportCloudinaryFieldclassPost(models.Model):author=models.ForeignKey('auth.User')title=models.CharField(max_length=200)text=models.TextField()create_date=models.DateTimeField(default=timezone.now)published_date=models.DateTimeField(blank=True,null=True)image_url=CloudinaryField('imagem',blank=True,null=True)defpublish(sefl):self.published_date=timezone.now()self.save()def__str__(self):returnself.title
views.py
defpost_new(request):upload_result=Nonethumbnail=Noneifrequest.method=="POST":
form = PostForm(request.POST, request.FILES)
if form.is_valid():
file = request.FILES['image_url']
if file:
upload_result = cloudinary.uploader.upload(file)
thumbnail, option = cloudinary_url(upload_result['public_id'], format="jpg", crop="fill", width=100, height=100)
post = form.save(commit=False)
post.author = request.user
post.published_date = timezone.now()
post.save()
return redirect('post_detail', pk=post.pk)
else:
form = PostForm()
return render(request, 'blog/post_edit.html', {'form': form})
post_edit.html
{% extends 'blog/base.html' %}
{% load cloudinary %}
{% block content %}
<h1>Nova postagem</h1>
<form action="" method="post" class="post-form" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_table }}
<br />
<div class="col-md-3">
<input type="submit" value="Salvar" class="btn btn-success">
</div>
</form>
{% endblock %}
If anyone can, include the cloudinary tag.