码迷,mamicode.com
首页 > 其他好文 > 详细

Django简单搭建编辑页面

时间:2020-05-27 09:15:31      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:ref   删除   div   ever   tst   doc   pat   info   oca   

技术图片

 

技术图片

 

技术图片

 

from django.shortcuts import render, reverse, HttpResponse, redirect
from app01 import models


# Create your views here.


def modify(request):
    all_course_obj_list = models.Course.objects.all()
    return render(request, modify_page.html, locals())


def modify_1(request):
    course_obj = models.Course.objects.filter(id=request.GET.get(course_id)).first()
    msg = 这是课程<{}>的修改页面.format(course_obj.course_name)
    return HttpResponse(msg)


def modify_2(request):
    course_obj = models.Course.objects.filter(id=request.GET.get(course_id)).first()
    course_obj.delete()
    return redirect(/modify/)

 

from django.conf.urls import url
from django.contrib import admin
from app01 import views as app01_views

urlpatterns = [
    url(r^admin/, admin.site.urls),
    url(r^modify/, app01_views.modify),
    url(r^modify_1/, app01_views.modify_1),
    url(r^modify_2/, app01_views.modify_2)
]

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑页面</title>
    {% load static %}
    <link rel="stylesheet" href="{% static ‘Bootstrap337/css/bootstrap.min.css‘ %}">
    <script src="{% static ‘Bootstrap337/js/bootstrap.min.js‘ %}"></script>
</head>
<body>
<h1 class="text-center">编辑页面</h1>
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <table class="table table-bordered table-hover table-striped">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>课程名称</th>
                    <th>课程等级</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for course_obj in all_course_obj_list %}
                    <tr>
                        <td>{{ course_obj.id }}</td>
                        <td>{{ course_obj.course_name }}</td>
                        <td>{{ course_obj.course_level }}</td>
                        <td>
                            <a href="/modify_1/?course_id={{ course_obj.id }}" class="btn btn-info btn-sm">修改</a>
                            <a href="/modify_2/?course_id={{ course_obj.id }}" class="btn btn-danger btn-sm">删除</a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>

 

Django简单搭建编辑页面

标签:ref   删除   div   ever   tst   doc   pat   info   oca   

原文地址:https://www.cnblogs.com/caoyu080202201/p/12970138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!