django - TypeError at /add/ unhashable type: 'list' -


i got following traceback when try save inline formset in django:

django version: 1.10 python version: 3.5.1 installed applications: ['django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'books',  'bootstrapform'] 

traceback:

file "d:\virtualenv\lib\site-packages\django\core\handlers\exception.py" in inner   39.             response = get_response(request)  file "d:\virtualenv\lib\site-packages\django\core\handlers\base.py" in _get_response   187.                 response = self.process_exception_by_middleware(e, request)  file "d:\virtualenv\lib\site-packages\django\core\handlers\base.py" in _get_response   185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)  file "d:\virtualenv\lib\site-packages\django\views\generic\base.py" in view   68.             return self.dispatch(request, *args, **kwargs)  file "d:\virtualenv\lib\site-packages\django\views\generic\base.py" in dispatch   88.         return handler(request, *args, **kwargs)  file "d:\virtualenv\inlineformset\books\views.py" in post   27.             return self.form_valid(form, formset)  file "d:\virtualenv\inlineformset\books\views.py" in form_valid   52.         return redirect(self.object.get_absolute_url())  file "d:\virtualenv\lib\site-packages\django\shortcuts.py" in redirect   56.     return redirect_class(resolve_url(to, *args, **kwargs))  file "d:\virtualenv\lib\site-packages\django\shortcuts.py" in resolve_url   147.         return reverse(to, args=args, kwargs=kwargs)  file "d:\virtualenv\lib\site-packages\django\urls\base.py" in reverse   91.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))  file "d:\virtualenv\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix   343.         possibilities = self.reverse_dict.getlist(lookup_view)  file "d:\virtualenv\lib\site-packages\django\utils\datastructures.py" in getlist   140.             return super(multivaluedict, self).__getitem__(key) 

my views:

class formsetmixin(object):     object = none      def get(self, request, *args, **kwargs):         if getattr(self, 'is_update_view', false):             self.object = self.get_object()         form_class = self.get_form_class()         form = self.get_form(form_class)         formset_class = self.get_formset_class()         formset = self.get_formset(formset_class)         return self.render_to_response(self.get_context_data(form=form, formset=formset))      def post(self, request, *args, **kwargs):         if getattr(self, 'is_update_view', false):             self.object = self.get_object()         form_class = self.get_form_class()         form = self.get_form(form_class)         formset_class = self.get_formset_class()         formset = self.get_formset(formset_class)         if form.is_valid() , formset.is_valid():             return self.form_valid(form, formset)         else:             return self.form_invalid(form, formset)      def get_formset_class(self):         return self.formset_class      def get_formset(self, formset_class):         return formset_class(**self.get_formset_kwargs())      def get_formset_kwargs(self):         kwargs = {             'instance': self.object         }         if self.request.method in ('post', 'put'):             kwargs.update({                 'data': self.request.post,                 'files': self.request.files,             })         return kwargs      def form_valid(self, form, formset):         self.object = form.save()         formset.instance = self.object         formset.save()         return redirect(self.object.get_absolute_url())      def form_invalid(self, form, formset):         return self.render_to_response(self.get_context_data(form=form, formset=formset))   class authorcreateview(formsetmixin, createview):     template_name = 'books/author_and_books_form.html'     model = author     form_class = authorform     formset_class = bookformset   class authorupdateview(formsetmixin, updateview):     template_name = 'books/author_and_books_form.html'     is_update_view = true     model = author     form_class = authorform     formset_class = bookformset   class booklist(listview):     model = book   class bookdetail(detailview):     model = book   class authorlist(listview):     model = author   class authordetail(detailview):     model = author 

can suggest me way fix errors?

from question , comments, think need check following things correct:

your get_absolute_url should have reverse method added commments:

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

after should check templates correctly reverse 'book_list' appropriate arguments. suppose:

<a href="{% url 'books:book_list' %}">books</a>  

and check urls, should like:

url(r'^$', views.booklist.as_view(), name='book_list'), url(r'^(?p<pk>\d+)/$', views.bookdetail.as_view(), name='book_detail'), 

hope help.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -