Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRafael Risco
31,535 PointsProblems with DeleteView: 'str' object is not callable
models.py
class Team(models.Model): name = models.CharField(max_length=255) coach = models.ForeignKey(User, related_name='teams', on_delete="CASCADE") practice_location = models.CharField(max_length=255)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse("teams:detail", kwargs={"pk": self.pk})
views.py
class TeamDeleteView(DeleteView): model = models.Team success_url = reverse_lazy("teams:list")
urls.py
urlpatterns = [ url(r'^$', views.TeamListView.as_view(), name='list'), url(r'^(?P<pk>\d+)/$', views.TeamDetailView.as_view(), name='detail'), url(r'^create/$', views.TeamCreateView.as_view(), name="create"), url(r'^edit/(?P<pk>\d+)/$', views.TeamUpdateView.as_view(), name='update'), url(r'^delete/(?P<pk>\d+)/$', views.TeamDeleteView.as_view(), name='delete'), ]
team_confirm_delete.html
{% extends "teams/_layout.html" %}
{% block body_content %} <h1>Delet {{ team.name }}?</h1>
<form method="POST"> {% csrf_token %} {{ form.as_p }} <input type="submit" class="btn btn-danger" value="Delete"> <a href="{% url 'teams:detail' pk=team.pk %}">Cancel</a> </form> {% endblock %}
Traceback
Environment:
Request Method: POST Request URL: http://127.0.0.1:8000/teams/delete/2/
Django Version: 2.0.3 Python Version: 3.6.5 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'teams'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\exception.py" in inner
- response = get_response(request)
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
- response = self.process_exception_by_middleware(e, request)
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
- response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\views\generic\base.py" in view
- return self.dispatch(request, *args, **kwargs)
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\views\generic\base.py" in dispatch
- return handler(request, *args, **kwargs)
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\views\generic\edit.py" in post
- return self.delete(request, *args, **kwargs)
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\views\generic\edit.py" in delete
- self.object.delete()
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py" in delete
- collector.collect([self], keep_parents=keep_parents)
File "C:\Users\Carlos Juri\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\deletion.py" in collect
- field.remote_field.on_delete(self, field, sub_objs, self.using)
Exception Type: TypeError at /teams/delete/2/ Exception Value: 'str' object is not callable
Alex Koumparos
Python Development Techdegree Student 36,887 PointsAlex Koumparos
Python Development Techdegree Student 36,887 PointsHi Rafael,
Please use proper Markdown formatting to avoid having your code mangled.
Cheers
Alex