简体   繁体   中英

upgraded from django 1.1 to 2.2, - (error) post_detail_view() got an unexpected keyword argument 'day'

(models.py) from django.utils import timezone

class Post(models.Model):

publish = models.DateTimeField(default=timezone.now)

def get_absolute_url(self):
    return reverse ('post_detail',args= 
    [self.publish.year,self.publish.strftime('%m'),self.publish.strftime('%d'),self.slug])

views.py

def post_detail_view(request,year,month,post):

 post=get_object_or_404(Post,slug=post,status='published',publish__year='year',publish__month='month',publish__day='day')
    return render(request,'blog/post_detail.html',{'post':post})

** gives error as -- post_detail_view() got an unexpected keyword argument 'day'

please help

url.py

re_path('(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<post>[-\w]+)/$',views.post_detail_view,name='post_detail')

I wil guess.

You have day ( (?P<day>\d{2}) ) in

re_path('(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/...', views.post_detail_view, ...)

so it may get url with day and send this day as argument to post_detail_view

but you don't have day in

def post_detail_view(request,year,month,post):

so it has problem what to do with this day .

Maybe simply add day

def post_detail_view(request,year,month,  day,  post):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM