当前位置:网站首页>[量化投资系统]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}}"
边栏推荐
- Markdown skill tree (7): separator and reference
- Fluent imitates uiswitch
- tf.to_int64
- Schnuka: 3D visual inspection scheme 3D visual inspection application industry
- Select distinct on statement in kingbasees
- Detailed explanation of top and free commands
- 帆船动力学仿真分析
- Detailed design of PLC program control system for washing machine
- [FreeRTOS] interrupt mechanism
- 【工控老马】PLC六路抢答器系统设计详解
猜你喜欢

蓝桥杯——13届第二批试题解析

Imx6dl4.1.15 supports EIM bus (upper) - actual operation and modification.

excel高级绘图技巧100讲(六)-甘特图在项目进度上的实战应用案例

Roblox sword nine sword two

Postman pre request

ShapeShifter: Robust Physical Adversarial Attack on Faster R-CNN Object Detector

Unexpected exception ... code: Badrequest when downloading Xilinx 2018.2

TREE ALV 展开Node或者点击Toolbar按钮时DUMP(CL_ALV_TREE_BASE==============CP|SET_ITEMS_FOR_COLUMN)

VMware vcenter/ESXI系列漏洞总结

Matlab Simulink simulation and analysis of power grid sweep frequency
随机推荐
编译原理王者之路
What is a Test Architect
软件测试鸾音鹤信
Dump (cl\alv\tree\base================================cp|set\items\for\column) when expanding node or clicking toolbar button
cv2.cvtColor
KingbaseES V8R6集群维护案例之--单实例数据迁移到集群案例
ES中配置ext.dic文件不生效的原因
【工控老马】洗衣机PLC程序控制系统设计详解
[translation] E-Cloud. Large scale CDN using kubeedge
TF.Slim的repeat和stack操作
tf.to_int64
Detailed explanation of communication principle between [industrial control old horse] single chip microcomputer and Siemens S7-200
施努卡:视觉定位系统厂家 什么是视觉定位系统
游标长时间open导致表无法vacuum问题
查看tensorflow是否支持GPU,以及测试程序
Blue Bridge Cup -- Analysis of the second batch of test questions of the 13th session
Use of parameter in Simulink for AUTOSAR SWC
Perceiving healthy life, enabling boundless connection -- contributing to openharmony 3.1 ecological construction
Markdown skill tree (8): code blocks
Reflection modification final