Why is Django product editing not working. Reverse for 'edit' not found?

I'm trying to edit a product (without using forms.py) but I get an error Reverse for 'edit' not found. 'edit' is not a valid view function or pattern name.

vievs.py

def edit(request, id):
    if (request.method == 'POST'):
        obj, update = Posts.objects.update_or_create(title=request.POST.get("title"))
        obj.text=request.POST.get("text")
        obj.date=request.POST.get("date")
        obj.image=request.POST.get("image")

        obj.save()

    return render(request, 'edit.html')

html

<form action="{% url "blog:edit" %}" method="post">
        {% for el in posts %}
        {% csrf_token %}
        <input type="text" placeholder="Название" name="title" value="{{ el.title }}"><br>
        <textarea placeholder="Текст статьи" rows="8" cols="80" name="text"></textarea><br>
        <input type="file" name="image"><br>
        <button type="submit">Добавить статью</button>
        {% endfor %}
      </form>

You need to define the view in your blog app's urls.py file. Something like this:

urlpatterns = [
    # ... other patterns
    path('<int:id>/edit/',views.edit,name='edit'),
]
Back to Top