Django中二级路由无法生效问题?_MYSQL_编程问答

Django中二级路由无法生效问题?

来源:互联网  时间:2018/1/27 12:24:11

关于网友提出的“ 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的代码

上一篇再次安装mySql,找不到文件怎么办?
下一篇mysql两表关联查询
明星图片
相关文章
《 Django中二级路由无法生效问题?》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)