反向重定向不工作,但将数据插入到数据库
问题描述:
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
我得到以下反向重定向不工作,但将数据插入到数据库
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
同样只是一个新手
答
你传递kwargs
到reverse
作为设置这个错误,什么时候应该是字典:
kwargs={'pk': self.pk}
# ^