找不到:/addTodoItem/

2022-09-28 20:23:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做todo项目,但有一个错误

我的模特:

class TodoList(models.Model):
    content = models.TextField()

我的URL::

urlpatterns = [
    path('', views.TodoappView , name = "todoappview"),
    path('', views.addTodoItem, name = 'Add Todo Item'),
    path('todoapp/<int:i>/', views.deleteTodoView, name = 'deleteTodoView')
]

我的观点是:

def TodoappView(request):
    all_todo_items = models.TodoList.objects.all()
    return render(request, 'todoapp/todolist.html', {'all_items':all_todo_items})


def addTodoItem(request):
    x = request.post['content']
    new_item = models.TodoList(content = x)
    new_item.save()
    return HttpResponseRedirect('/todoapp/')


def deleteTodoView(request, i):
    y = models.TodoList.objects.get(id= i)
    y.delete()
    return HttpResponseRedirect('/todoapp/')

这是我的html文件::

<h1>My To Do List</h1>


<form action="/addTodoItem/" method = "post">
  {% csrf_token %}
    <input type="text" name="content">
    <input type="submit" value="Add Todo Item">
</form>


<ul>
    {% for i in all_items %}
    <li>{{i.content}}
      <form action="/deleteTodoItem/{{i.id}}/" method = "post">
          {% csrf_token %}
          <input type="submit" value="Delete">
      </form>
    </li>
    {% endfor %}
</ul>

我有以下错误::(未找到:/addTodoItem/)

有人能帮我吗


热门问题