<form action="<%=path %>/admin?type=adminAdd" name="formAdd" method="post">是什么意思
时间: 2023-12-05 12:15:47 浏览: 113
As an AI language model, I am unable to perceive the concept of null. In computer science, null is a special value used to represent a lack of a value or an empty value. It is often used when a variable or object has not been assigned a value or when a value is intentionally left empty.
相关问题
{% extends "admin/base.html" %} {% block content %} <div class="container-fluid"> <div class="row"> <div class="col-md-6"> <h2>药品列表</h2> <table class="table"> <thead> <tr> <th>ID</th> <th>药品名称</th> <th>操作</th> </tr> </thead> <tbody> {% for drug in drugs %} <tr> <td>{{ drug.id }}</td> <td>{{ drug.drug_name }}</td> <td> <a href="{% url 'admin:drug_db_drug_list_change' drug.id %}" class="btn btn-primary btn-sm">编辑</a> <form action="{% url 'admin:drug_db_drug_list_delete' drug.id %}" method="post" class="d-inline"> {% csrf_token %} <button class="btn btn-danger btn-sm">删除</button> </form> </td> </tr> {% empty %} <tr> <td colspan="3">暂无药品</td> </tr> {% endfor %} </tbody> </table> <a href="{% url 'admin:drug_db_drug_list_add' %}" class="btn btn-success">添加新药品</a> </div> <div class="col-md-6"> <h2>药品相互作用</h2> <table class="table"> <thead> <tr> <th>ID</th> <th>药品1</th> <th>药品2</th> <th>相互作用</th> <th>操作</th> </tr> </thead> <tbody> {% for interaction in interactions %} <tr> <td>{{ interaction.id }}</td> <td>{{ interaction.drug1 }}</td> <td>{{ interaction.drug2 }}</td> <td>{{ interaction.interaction }}</td> <td> <a href="{% url 'admin:drug_db_drug_interaction_change' interaction.id %}" class="btn btn-primary btn-sm">编辑</a> <form action="{% url 'admin:drug_db_drug_interaction_delete' interaction.id %}" method="post" class="d-inline"> {% csrf_token %} <button class="btn btn-danger btn-sm">删除</button> </form> </td> </tr> {% empty %} <tr> <td colspan="5">暂无药品相互作用</td> </tr> {% endfor %} </tbody> </table> <a href="{% url 'admin:drug_db_drug_interaction_add' %}" class="btn btn-success">添加新药品相互作用</a> </div> </div> </div> {% endblock %} 为上述代码设置相应的视图和URL配置,并将这些视图和操作注册到Django admin页面中。
首先,需要定义视图函数来渲染药品列表和药品相互作用列表的页面。可以使用Django的通用视图类(Generic Views)来完成。
```python
from django.views.generic import TemplateView
class DrugListView(TemplateView):
template_name = "admin/drug_db/drug_list.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["drugs"] = Drug.objects.all()
context["interactions"] = DrugInteraction.objects.all()
return context
```
上述视图函数将会渲染名为 `drug_list.html` 的模板文件,并且会将所有的药品和药品相互作用传递给模板。
接着,需要定义URL配置来匹配请求并将其分配给对应的视图函数。
```python
from django.urls import path
from .views import DrugListView
app_name = "drug_db"
urlpatterns = [
path("", DrugListView.as_view(), name="drug_list"),
]
```
最后,需要将上述URL配置和视图函数注册到Django admin页面中。
```python
from django.contrib import admin
from django.urls import path, include
from drug_db.views import DrugListView
admin.site.site_header = "药品管理系统"
admin.site.site_title = "药品管理系统"
admin.site.index_title = "欢迎使用药品管理系统"
urlpatterns = [
path("admin/", admin.site.urls),
path("drug_db/", include("drug_db.urls")),
]
admin.site.register_view("drug_db/drug_list/", view=DrugListView.as_view(), name="drug_db_drug_list")
```
上述代码将会在Django admin页面的左侧菜单中添加一个名为“药品列表”的链接,点击链接将会显示药品列表和药品相互作用列表的页面。
阅读全文