会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132575个问题
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于MyCat实现分库分表和读写分离 23866楼
JAVA 全系列/第五阶段:JavaWeb开发/JSP技术详解(旧) 23867楼
JAVA 全系列/第五阶段:JavaWeb开发/JSP技术详解(旧) 23868楼

老师,出现了如下问题,报了这个错误

# encoding=utf-8
from django.shortcuts import render, render_to_response, get_object_or_404


# Create your views here.
from template_app.models import Student


def first(request):
    context = {
        'first_name': 'John',
         'last_name': 'Doe'
    }
    return render_to_response('template_app/first.html',context)


def second(request,pk):
    student = get_object_or_404(Student,pk=pk)

    dict_data = {
        'dict_key1': 'terry',
        'dict_key2': 'marry'
    }
    li_data = [
        '北京', '上海', '深圳'
    ]
    return render_to_response('template_app/second.html',{
        'student': student,
        'dict_data': dict_data,
        'li_data': li_data
    })


def students(request):
    student_li = get_object_or_404(Student)
    context = {
        'students_li': student_li
    }
    return render_to_response('template_app/students.html',context)


def url_test(request):
    return render_to_response('template_app/url_test.html')
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>URL标签测试</title>
</head>
<body>
    URL标签测试
    <ul>
        <li>所有学生信息查询:<a href={% url 'template_app:second' %}>点击链接</a></li>
    </ul>
</body>
</html>
# encoding=utf-8
from django.urls import path
from . import views

app_name = 'template_app'

urlpatterns = [
    path('first/',views.first),
    path('second/<int:pk>/',views.second,name='second'),
    path('students/',views.students,name='students'),
    path('url_test/',views.url_test),
]

QQ图片20210314191405.png

Python 全系列/第十二阶段:Python_Django3框架/Django初级 23869楼
JAVA 全系列/第八阶段:Linux入门到实战/Maven 23871楼
WEB前端全系列/第十九阶段:Vue2知识体系(旧)/Vue基础知识 23875楼
WEB前端全系列/第七阶段:ECMAScript6新特性模块/ES6第一部分 23876楼
JAVA 全系列/(隐藏)第二十三阶段:数字货币交易所项目/服务中台_后台管理系统的开发 23877楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637