python - NoReverseMatch after upgrading to Django 1.6 from 1.4 -
finally upgraded project 1.6 , i'm having trouble urls , class based views.
i have form starts this:
<form action="{{ project.get_absolute_url }}" method="post" id="editproject" >
and project model includes this:
@permalink def get_absolute_url(self): return ('project_url', (), {'slug': self.slug})
on trying load page i'll error:
noreversematch @ /teamslug1/projectslug1/teamid1/projectid1/ reverse 'project_url' arguments '()' , keyword arguments '{'slug': u'projectslug1'}' not found. 1 pattern(s) tried: ['(?p<teamslug>[^\\.]+)/(?p<projectslug>[^\\.]+)/(?p<teamid>[^\\.]+)/(?p<projectid>[^\\.]+)/$']
if wrap form variable in quotes:
<form action="{{ "project.get_absolute_url" }}" method="post" id="editproject" >
it won't error out on loading when post form it'll result in url this: http://0.0.0.0:5000/teamslug1/projectslug1/teamid1/projectid1/project.get_absolute_url
, doesn't exist.
here's urls.py info:
url(r'^(?p<teamslug>[^\.]+)/(?p<projectslug>[^\.]+)/(?p<teamid>[^\.]+)/(?p<projectid>[^\.]+)/$', 'ideas.views.projects', name='project_url'),
any ideas?
this doesn't problem specific django 1.6 or class based views. problem get_absolute_url
method doesn't match url pattern.
firstly, wrapping variable in quotes incorrect. django treats string, browser treats relative link, , posts form wrong url.
the project_url
url pattern has 4 keyword arguments get_absolute_url
method specifies slug
, isn't 1 of arguments. expect get_absolute_url
method like:
@permalink def get_absolute_url(self): return ('project_url', (), {'teamslug': self.teamslug, 'projectslug': self.projectslug, 'projectid': self.projectid, 'teamid ': self.teamid, })
note docs recommend use reverse
instead of permalink
decorator.
from django.core.urlresolvers import reverse def get_absolute_url(self): return reverse('project_url', kwargs={'teamslug': self.teamslug, 'projectslug': self.projectslug, 'projectid': self.projectid, 'teamid ': self.teamid, })
Comments
Post a Comment