当前位置:网站首页>[量化投资系统]Django从数据库中实现筛选及分页
[量化投资系统]Django从数据库中实现筛选及分页
2022-06-29 06:40:00 【Time.J】
**
Django筛选数据分类遇到只能跳转第一页,第二页无数据的情况。
**
1.models.py创建模型
class User(models.Model):
uname= models.CharField(max_length=20)
uEmail= models.CharField(max_length=35)
uphone= models.CharField(max_length=15)
2.views.py从数据库中筛选数据
if request.method == 'POST':
name = request.POST.get('code')
else:
name = request.GET.get('code')
UserList = User.objects.filter(uphone=name).order_by()
3.分页器
paginator = Paginator(UserList,2) # 3 posts in each page
page = request.GET.get('page')
try:
pagedata = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer deliver the first page
pagedata = paginator.page(1)
except EmptyPage:
# # If page is out of range deliver last page of results
pagedata = paginator.page(paginator.num_pages)
4.传递数据
return (render(request,'Qt15606/students.html',{
'name':name,'page': pagedata,'pagedata': pagedata}))
5.前端界面students.html
<div class="pagination">
<span class="step-links">
{
% if page.has_previous %}
<a style="font-weight:bold;color:#383957;" href="?page=1&code={
{name}}" >第一页</a>
<a class="btn btn-primary btn-lg active" href="?page={
{page.previous_page_number}}&code={
{name}}">上一页</a>
{
% endif %}
<span style="font-weight:bold;color:#383957" class="current">
第{
{
page.number}}页 ··· 共 {
{
page.paginator.num_pages}}页
</span>
{
% if page.has_next %}
<a class="btn btn-primary btn-lg active" href="?page={
{page.next_page_number }}&code={
{name}}">下一页</a>
<a class="btn btn-primary btn-lg active" href="?page={
{page.paginator.num_pages}}&code={
{name}}">最后一页</a>
{
% endif %}
</span>
</div>
其中最重要的一步是要在链接上加筛选的条件。href="?page={ {page.next_page_number }}&code={ {name}}"
边栏推荐
- Kingbasees v8r6 cluster maintenance case - data migration between clusters
- 软件测试鸾音鹤信
- Markdown skill tree (3): title
- Matlab Simulink simulation and analysis of power grid sweep frequency
- 面试官:为什么数据库连接很消耗资源,资源都消耗在哪里?
- 查看tensorflow是否支持GPU,以及测试程序
- Appium自动化测试基础 — ADB常用命令(二)
- [industrial control old horse] detailed explanation of the design scheme of the running lamp control system based on Siemens S7-200PLC
- [old horse of industrial control] detailed explanation of Siemens PLC s7-300scl programming
- 感知健康生活 赋能无界连接 ——为OpenHarmony 3.1生态构建贡献芯海力量
猜你喜欢

并发幂等性防抖

Explanation of swing transformer theory

搭建jenkins环境并自动关联打包好的工程jar进行自动发布

postman预处理/前置条件Pre-request

【域渗透提权】CVE-2020-1472 NetLogon 权限提升漏洞

Use of parameter in Simulink for AUTOSAR SWC

Appium automation test foundation ADB common commands (III)

Markdown skill tree (5): picture

【工控老马】基于西门子S7-200PLC的跑马灯控制系统的设计方案详解

【工控老马】洗衣机PLC程序控制系统设计详解
随机推荐
SYSTEMd management node exporter
pycharm的虚拟环境如何共享到jupyter-lab
Blue Bridge Cup -- Analysis of the second batch of test questions of the 13th session
Swin Transformer理论讲解
[old horse of industrial control] detailed explanation of Siemens PLC s7-300scl programming
Detailed explanation of route (Jiuyang Scripture)
KingbaseES V8R6集群维护案例之--单实例数据迁移到集群案例
蓝桥杯——最小框架
What tools do testers need to know
Explanation of swing transformer theory
Appium automation test foundation ADB common commands (III)
TF. Repeat and stack operations of slim
ShapeShifter: Robust Physical Adversarial Attack on Faster R-CNN Object Detector
Imx6dl4.1.15 supports EIM bus (upper) - actual operation and modification.
Concurrent idempotent anti shake
tf.count_nonzero
Select distinct on statement in kingbasees
Markdown skill tree (4): link
498. 对角线遍历(模拟)
4 years of working experience, and you can't tell the five communication modes between multithreads. Can you believe it?