Django and Cloudinary error - can’t use the string Pattern on a bytes-like Object

Asked

Viewed 104 times

1

I’m trying to make a simple app: I made the tutorial of Django Girls and now I’m trying to use the same including also an image using the Cloudinary

But I’m having the following mistake:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Error happens on line upload_result = cloudinary.uploader.upload(file) of the archive views.py

Follows code

models.py

from django.db import models
from django.utils import timezone
from cloudinary.models import CloudinaryField

class Post(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)

def publish(sefl):
    self.published_date = timezone.now()
    self.save()

def __str__(self):
    return self.title

views.py

def post_new(request):
    upload_result = None
    thumbnail = None

    if request.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 tag cloudinary.

1 answer

2


It had this same problem, it turns out that the library was incompatible with some new functions of Python 3.x and corrected them in version 1.3.1

Updates the Cloudinary package version to 1.3.1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.