working fine with sqllite but not showing result in mysql

21 views
Skip to first unread message

tribhuvan kishor

unread,
Jan 14, 2019, 1:08:10 PM1/14/19
to django...@googlegroups.com
this view is retrieving data with SQlite but not fetching data in MySQL saying no data found.


def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post,
status='published',
publish__year=year,
publish__month=month,
publish__day=day)

return render(request,
'blog/post/details.html',
{'post': post})
--
regards 
Tribhuvan Kishor Bhaskar

Alex Kimeu

unread,
Jan 14, 2019, 1:55:10 PM1/14/19
to django...@googlegroups.com
Have you configured MySQL correctly?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACiphSVVyMgpNmgFj16ROZGqpohaq0fYJKV2bES4D1aVeg1LbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
"It's when nothing happens that anything can happen."
https://kodenaut.github.io/
+254 723494571

tribhuvan kishor

unread,
Jan 14, 2019, 2:23:05 PM1/14/19
to django...@googlegroups.com
yes all things are working fine like post list are working fine

from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.views.generic import ListView
from .models import Post

def post_list(request):
object_list = Post.published.all()
paginator = Paginator(object_list, 3) # 3 posts in each page
page = request.GET.get('page')
try:
posts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer deliver the first page
posts = paginator.page(1)
except EmptyPage:
# If page is out of range deliver last page of results
posts = paginator.page(paginator.num_pages)
return render(request,
'blog/post/list.html',
{'page': page,
'posts': posts})

# Create your views here.
def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post,
status='published',
publish__year=year,
publish__month=month,
publish__day=day)

return render(request,
'blog/post/details.html',
{'post': post})

class PostListView(ListView):
queryset = Post.published.all()
context_object_name = 'posts'
paginate_by = 3
template_name = 'blog/post/list.html'

def test_test(request):
return render(request,'blog/post/test.html')


For more options, visit https://groups.google.com/d/optout.


--
regards 
Tribhuvan Kishor Bhaskar

Alex Kimeu

unread,
Jan 14, 2019, 3:20:37 PM1/14/19
to django...@googlegroups.com
Kindly post your urls mappings.


For more options, visit https://groups.google.com/d/optout.

Danylo K.

unread,
Jan 14, 2019, 3:41:15 PM1/14/19
to django...@googlegroups.com
I have the same issue. In MySQL, search works fine by the year part, but not by the month and day parts.

Cheers!

Danylo K.

unread,
Jan 14, 2019, 3:41:42 PM1/14/19
to django...@googlegroups.com
if you change the code to this, it will work:

   post = get_object_or_404(Post, slug=post,
status='published',
                             publish__year=year)
# publish__month=month,
# publish__day=day)

tribhuvan kishor

unread,
Jan 18, 2019, 8:59:18 AM1/18/19
to django...@googlegroups.com
its the shortcut i did that it is working. but the issue is still the same. it just a bypass :P



For more options, visit https://groups.google.com/d/optout.

tribhuvan kishor

unread,
Jan 18, 2019, 9:00:57 AM1/18/19
to django...@googlegroups.com
from django.urls import path
from . import views 


app_name = 'blog'
urlpatterns = [
    # post views
    # path('', views.post_list, name='post_list'),
    path('', views.PostListView.as_view(), name='post_list'),
    path('<int:year>/<int:month>/<int:day>/<slug:post>/',
         views.post_detail,
         name='post_detail'),

Reply all
Reply to author
Forward
0 new messages