我正尝试在Django中创建一个民意调查应用程序,并且正在为问题创建一个详细信息页面,但是当打开我的详细信息时,它会在浏览器中打开,但是我一直在获取“ polls_detail()确实有2个参数(给定1个)”。
以下是一些代码:
models.py
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __unicode__(self):
return self.choice_text
``````````````````````````````````````````````````````````````````````````
views.py
```````````````````````````````````````````````````````````````````````````
def polls(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'poll/polls.html', context)
# Create your views here.
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/polls_detail.html', {'question': question})
````````````````````````````````````````````````````````````````````````````
urls.py
`````````````````````````````````````````````````````````````````````````````
urlpatterns = [
url(r'^polls/$',views.polls, name="polls"),
url(r'^detail/$',views.detail, name="detail"),
````````````````````````````````````````````````````````````````````````````
It should return the page with the detail page with the question text on it.
Thanks