Joe Kasedde Joe Kasedde - 2 months ago 14
Python Question

Reverse redirect does not work but inserts data into db

from django.db import models
from django.core.urlresolvers import reverse


class Gallery(models.Model):
Title = models.CharField(max_length=250)
Category = models.CharField(max_length=250)
Gallery_logo = models.CharField(max_length=1000)

def get_absolute_url(self):
return reverse('photos:detail', kwargs={'pk', self.pk})

def __str__(self):
return self.Title + '_' + self.Gallery_logo


class Picture (models.Model):
Gallery = models.ForeignKey(Gallery, on_delete=models.CASCADE)
Title = models.CharField(max_length=250)
Artist = models.CharField(max_length=250)
Price = models.CharField(max_length=20)
interested = models.BooleanField(default=False)

def __str__(self):
return self.Title


Am getting this error below

TypeError at /photos/gallery/add/
_reverse_with_prefix() argument after ** must be a mapping, not set
Request Method: POST
Request URL: http://127.0.0.1:8000/photos/gallery/add/
Django Version: 1.10.1
Exception Type: TypeError
Exception Value:
_reverse_with_prefix() argument after ** must be a mapping, not set
Exception Location: C:\Users\JK\AppData\Local\Programs\Python\Python35\lib\site-packages\django-1.10.1-py3.5.egg\django\urls\base.py in reverse, line 91
Python Executable: C:\Users\JK\AppData\Local\Programs\Python\Python35\python.exe
Python Version: 3.5.2
Python Path:
['C:\\Users\\JK\\PycharmProjects\\catalog',
'C:\\Users\\JK\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-packages\\django-1.10.1-py3.5.egg',
'C:\\Users\\JK\\PycharmProjects\\catalog',
'C:\\Users\\JK\\AppData\\Local\\Programs\\Python\\Python35\\python35.zip',
'C:\\Users\\JK\\AppData\\Local\\Programs\\Python\\Python35\\DLLs',
'C:\\Users\\JK\\AppData\\Local\\Programs\\Python\\Python35\\lib',
'C:\\Users\\JK\\AppData\\Local\\Programs\\Python\\Python35',
'C:\\Users\\JK\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-packages']
Server time: Fri, 30 Sep 2016 17:15:55 +0300


Again am just a newbie

Answer

You're passing kwargs to reverse as a set, when it should be a dictionary:

kwargs={'pk': self.pk}
#           ^