2017-07-24 64 views
0

你好,我在/ taskoftheday中得到一個類型錯誤(需要2個參數,但只給出1個)。類型錯誤詳細視圖Django

我不知道該怎麼辦才能修復它。我缺少什麼論點? 我想爲每個指南ID創建一個詳細的視圖。

這裏是我的代碼:

瀏覽:

from django.http import Http404 
from django.http import HttpResponse 
from django.shortcuts import render 
from models import Guide, Step, Sub_step 


def taskoftheday(request, guide_id): 
    try: 
     guide = Guide.objects.get(pk=guide_id) 
    except Guide.DoesNotExst: 
     raise Http404("Guide does not exist") 
    return render(request, 'taskoftheday/taskoftheday.html', {'guide': guide}) 


def detail_taskoftheday(request): 
    return render(render, 'taskoftheday/detail_taskoftheday.html') 

網址:

from django.conf.urls import url 

from . import views 

urlpatterns = [ 
    url(r'^$', views.taskoftheday, name="taskoftheday"), 
    url(r'(?P<guide_id>[0-9]+)/$', views.detail_taskoftheday, name='detail_taskoftheday'), 
] 

謝謝! :)

回答

1

您似乎將視圖名稱taskofthedaydetail_taskoftheday並列在您的views.py中。

taskoftheday應該採取一個唯一的參數 - request - 而detail_taskoftheday應採取既requestguide_id

def detail_taskoftheday(request, guide_id): 
    try: 
     guide = Guide.objects.get(pk=guide_id) 
    except Guide.DoesNotExst: 
     raise Http404("Guide does not exist") 
    return render(request, 'taskoftheday/detail_taskoftheday.html', {'guide': guide}) 

def taskoftheday(request): 
    return render(render, 'taskoftheday/taskoftheday.html') 
+0

奧基的感謝!我現在重新制作了它,但卻面臨另一個問題。我想使用taskoftheday函數直接顯示指南,就像詳細視圖一樣。我該怎麼做呢? – 9minday