При нажатии на странице project.html кнопки
Добавить задачу вылетает ошибка:
Reverse for 'add_task' with no arguments not found. 1 pattern(s) tried: ['my_projects/project(?P[^/]+)/add_task/$']
Request Method: GET
Request URL:
127.0.0.1:8000/my_projects/project2/add_task
помогите разобраться, только недавно начал изучать!!!
файл
urls.py:
app_name = 'table'
urlpatterns = [
path('', views.index, name = 'index'),
path('my_projects/', views.my_projects, name = 'my_projects'),
path('add_project/', views.add_project, name = 'add_project'),
path('my_projects/project<project_id>/', views.project, name = 'project'),
path('my_projects/project<project_id>/add_task/', views.add_task,
name = 'add_task'),
]
файл
views.py:
def project(request, project_id):
project = Project.objects.get(id = project_id)
statuses = project.status_set.order_by('id')
tasks = []
if statuses:
for status in statuses:
tasks += status.task_set.order_by('id')
context = {'project': project,'statuses': statuses, 'tasks': tasks}
return render(request, 'table/project.html', context)
def add_task(request, project_id):
if request.method != 'POST':
taskForm = TaskForm()
else:
taskForm = TaskForm(request.POST)
if taskForm.is_valid():
taskForm.save()
#return HttpResponseRedirect(reverse('table:project', project_id = project.id))
context = {'taskForm': taskForm}
return render(request, 'table/add_task.html', context)
файл
models.py:
class Project(models.Model):
name = models.CharField(max_length = 50)
description = models.TextField()
def __str__(self):
return str(self.name)
class Status(models.Model):
project = models.ForeignKey(Project, on_delete = models.CASCADE)
title = models.CharField(max_length = 50)
def __str__(self):
return str(self.title)
class Task(models.Model):
status = models.ForeignKey(Status, on_delete = models.CASCADE)
title = models.CharField(max_length = 300)
desctription = models.TextField()
def __str__(self):
if len(str(self.title)) < 50:
return str(self.title)
else:
return str(self.title)[:50] + "..."
файл
project.html:
{% extends 'table/base.html' %}
{% block content %}
<ul>
<p>{{project}}</p>
{% for status in statuses %}
<p1>
{{ status }}
<ul>
{% for task in tasks %}
{% if task.status == status %}
<li>{{ task }}</li>
{% endif %}
{% endfor %}
</ul>
</p1>
{% empty %}
<li>Нет статусов для задач</li>
{% endfor %}
</ul>
<a href="{% url 'table:add_task' project.id %}">Добавить новую задачу</a>
{% endblock content %}
файл
add_task.html:
{% extends 'table/base.html' %}
{% block content %}
<p>Поставьте новую задачу:</p>
<form action="{% url 'table:add_task' %}" method="POST">
{% csrf_token %}
{{ taskForm.as_p }}
<button name="submit">Добавить задачу</button>
</form>
{% endblock content %}
извините за громозкость, не могу понять где именно ошибка.