当前位置:网站首页>[量化投资系统]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}}"
边栏推荐
- matlab simulink 电网扫频仿真和分析
- DataTables screen error Popup
- Problem solving -- > online OJ (13)
- tf.compat.v1.global_variables
- Software testing
- Kingbasees v8r6 cluster maintenance case -- single instance data migration to cluster case
- 路由详解(九阳真经)
- Kingbasees v8r6 cluster maintenance case - data migration between clusters
- Schnuka: 3D visual inspection scheme 3D visual inspection application industry
- The table cannot be vacuumed because the cursor is open for a long time
猜你喜欢

Kyushu cloud helps Inner Mongolia's "counting from the east to the west" project to drive the smart new ecology of the surveying and mapping industry

Explanation of swing transformer theory

Appium自动化测试基础 — ADB常用命令(二)

施努卡:3d视觉检测方案 3d视觉检测应用行业

SQL 注入绕过(六)

Appium environment setup

Unexpected exception ... code: Badrequest when downloading Xilinx 2018.2
![[industrial control old horse] detailed explanation of the design scheme of the running lamp control system based on Siemens S7-200PLC](/img/c5/9383a02050c83b26bb56f4045b0774.png)
[industrial control old horse] detailed explanation of the design scheme of the running lamp control system based on Siemens S7-200PLC

呕心沥血总结出来的MySQL常见错误以及解决方法(二)

Perceiving healthy life, enabling boundless connection -- contributing to openharmony 3.1 ecological construction
随机推荐
ES中配置ext.dic文件不生效的原因
施努卡:视觉定位系统厂家 什么是视觉定位系统
游标长时间open导致表无法vacuum问题
Markdown skill tree (2): paragraph and emphasis
呕心沥血总结出来的MySQL常见错误以及解决方法(一)
Kingbasees v8r6 cluster maintenance case - data migration between clusters
小白大战指针 (上)
软件测试鸾音鹤信
Markdown skill tree (3): title
Cv:: mat and Base64 conversion (including picture compression and decompression)
excel高级绘图技巧100讲(六)-甘特图在项目进度上的实战应用案例
498. diagonal traversal (simulation)
Roblox sword nine sword two
TREE ALV 展开Node或者点击Toolbar按钮时DUMP(CL_ALV_TREE_BASE==============CP|SET_ITEMS_FOR_COLUMN)
How to solve the cross domain problem of mobile phone accessing the web in the web development scenario
Listen to textarea input through Keyup to change button style
Simulation analysis of sailing dynamics
[translation] E-Cloud. Large scale CDN using kubeedge
VMware vcenter/ESXI系列漏洞总结
KingbaseES V8R6集群维护案例之--单实例数据迁移到集群案例