[PYTHON] I would like to know about Django pagination.

I was studying with a reference book called Python Django I'm stumbling on "How do I move pages?" In 4-3 Pagination. first works fine, but prev, next, and last are inevitably Page not found. Can you tell me who you are? The source looks like this It's my first post, so I don't think it can be used well. I'm sorry django_app/hello/url.py from django.urls import path from . import views

urlpatterns=[ path('',views.index,name='index'), path('int:num',views.index,name='index'), path('create',views.create,name='create'), path('edit/int:num',views.edit,name='edit'), path('delete/int:num',views.delete,name='delete'), path('find',views.find,name='find'), path('check',views.check,name='check'), ]

django_app/hello/views.py from django.shortcuts import render from django.http import HttpResponse from django.shortcuts import redirect from .models import Friend from .forms import FriendForm from .forms import FindForm from django.db.models import Q from django.db.models import Count,Sum,Avg,Min,Max from .forms import CheckForm from django.core.paginator import Paginator

def index(request,num=1): data = Friend.objects.all() page = Paginator(data,3) params = { 'title': 'Hello', 'message':'', 'data': page.get_page(num), } return render(request,'hello/index.html',params)

create model def create(request): if (request.method == 'POST'): obj = Friend() friend = FriendForm(request.POST,instance=obj) friend.save() return redirect(to='/hello') params = { 'title' : 'Hello', 'form' : FriendForm(), } return render(request,'hello/create.html',params) def edit(request,num): obj = Friend.objects.get(id=num) if (request.method == 'POST'): friend = FriendForm(request.POST,instance=obj) friend.save() return redirect(to='/hello') params={ 'title' : 'Hello', 'id' : num, 'form' : FriendForm(instance=obj), } return render(request,'hello/edit.html',params) def delete(request,num): friend = Friend.objects.get(id=num) if (request.method == 'POST'): friend.delete() return redirect(to='/hello') params = { 'title' : 'Hello', 'id' : num, 'obj' : friend, } return render(request,'hello/delete.html',params)

def find(request): if (request.method == 'POST'): msg = request.POST['find'] form = FindForm(request.POST) sql = 'select * from hello_friend' if (msg != ''): sql += ' where ' + msg data = Friend.objects.raw(sql) msg = sql else: msg = 'search words...' form = FindForm() data =Friend.objects.all() params = { 'title' : 'Hello', 'message' : msg, 'form' :form, 'data' :data, } return render(request,'hello/find.html',params) def check(request): params={ 'title' : 'Hello', 'message' : 'check validation.', 'form' : CheckForm(), } if (request.method == 'POST'): obj = Friend() form = FriendForm(request.POST,instance=obj) params['form'] = form if (form.is_valid()): params['message'] = 'OK!' else: params['message'] = 'no good.' return render(request,'hello/check.html',params)

django_app/hello/template/hello/index.html {% load static %}

{{title}}

{{title}}

{{message|safe}}

{% for item in data %} {% endfor %}
id name age mail birthday
{{item.id}} {{item.name}} {{item.age}} {{item.mail}} {{item.birthday}}

Recommended Posts

I would like to know about Django pagination.
Python that I would like to recommend to programming beginners
Nice to meet you, I would like to introduce myself.
I tried to organize about MCMC.
I want to know how LINUX works!
I want to know more about individual developers. YouDev has been released.
[Django] Now that I know about make migrations and migrate, I've summarized them.
I want to pin Datetime.now in Django tests
Would you like to make a Twitter resume?
I didn't know much about Linux environment variables
[Recruitment] Would you like to exchange programming skills?
I implemented Google's Speech to text in Django
I want to upload a Django app to heroku
I tried Django
I convert AWS JSON data to CSV like this
I tried to create a table only with Django
I thought about how to learn programming for free.
Would you like to analyze your escape shame yourself?
I want to manipulate strings in Kotlin like Python!