关于网友提出的“ Django中二级路由无法生效问题?”问题疑问,本网通过在网上对“ Django中二级路由无法生效问题?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: Django中二级路由无法生效问题?描述:
我按照这个教程的part2部分http://www.liujiangblog.com/c...。可是到了视图部分,polls页面可以显示,其子页面无法显示。原先以为是我的环境配置出了问题,教程上是Django1.11.7,我原先用的Django2.0.1.卸载了2.0重新安装1.11.7之后,还是显示404错误。
求教问题出在哪里?
这是项目结构
下面是view.py
from django.http import HttpResponse
from .models import Question
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
output = ', '.join([q.question_text for q in latest_question_list])
return HttpResponse(output)
def detail(request, question_id):
return HttpResponse("You're looking at question %s." % question_id)
def results(request, question_id):
response = "You're looking at the results of question %s."
return HttpResponse(response % question_id)
def vote(request, question_id):
return HttpResponse("You're voting on question %s." % question_id)
model.py
from django.db import models
# Create your models here.
from django.db import models
from django.utils import timezone
import datetime
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
@python_2_unicode_compatible
class Choice(models.Model):
question = models.ForeignKey(Question,
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
这是polls/urls.py的代码