Я не получаю никакой ошибки, но также не получаю ни одного блога, Проблема с разбиением на страницы - PullRequest
0 голосов
/ 29 апреля 2020

Я не получаю никакой ошибки с этим кодом, но также не получаю никакого результата, он не показывает ни одного моего блога на странице. Я думаю, что HTML код неуместен. моя нумерация страниц не работает должным образом, прежде чем выдает ошибку порядка, затем я упорядочил ее по дате, и теперь она ничего не отображает и не выдает никакой ошибки, из-за которой трудно исправить

main. html

<!DOCTYPE html>
{% load static %}
<link rel="shortcut icon" href="{%  static 'img/favicon.png' %} ">
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Advice Lancing</title>


    <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> -->

    <!-- Bootstrap Core CSS -->
    <link type="text/css" href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">

    <!-- Theme CSS -->
    <link href="{% static 'css/clean-blog.min.css' %}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="{% static 'vendor/font-awesome/css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
    <link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <style>
img {
  border: 1px solid #ddd; /* Gray border */
  border-radius: 10px;  /* Rounded border */
  padding: 5px; /* Some padding */
  width: 450px; /* Set a small width */
}

/* Add a hover effect (blue shadow) */
img:hover {
  box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
}
</style>


</head>
<body> 


    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-custom navbar-fixed-top">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header page-scroll">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    Menu <i class="fa fa-bars"></i>
                </button>
                <a class="navbar-brand" href="{% url 'allblogs' %}">
                Advice lancing</a>


            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="{% url 'allblogs' %}">Home</a>
                    </li>
                    <li>
                        <a href="{% url 'about' %}">About</a>
                    </li>
                    <li>
                        <a href="{% url 'allblogs' %}">My Blogs</a>
                    </li>
                    <li>
                        <a href="{% url 'contact' %}">Contact Us</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

    <!-- Page Header -->
    <!-- Set your background image for this header on the line below. -->
    <!-- <header class="intro-header" style="background-image: url('img/home-bg.jpg')"> -->
    <header class="intro-header" style="background-image: url('static/img/home.jpg') ">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    <div class="site-heading">
                        <h1>Advice Lancing</h1>
                        <hr class="small">
                        <span class="subheading">Here You Write your Subheading</span>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->

    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                {% if tag %}
                <h2>Posts tagged with "{{ tag.name }}"</h2>
                {% endif %}
                {% for blog in blogs.all %}
                <div class="post-preview">
                    <a href="{% url 'detail' blog.id %}">
                        <h2 class="post-title">
                            {{ blog.title }}
                        </h2>
                        <h4 class="post-subtitle"><u>{{blog.publish_date|date:"d M Y"}}</u></h4>
                        <h3 class="post-subtitle">
                            {{ blog.subtitle}}
                        </h3>

                    </a>
                    <p class="post-meta">{{ blog.publish_date_pretty }}</p>
                </div>
                <br />
                  <img src = "{{ blog.image.url }}" class="thumbnail">
                <br />
                  <p>{{ blog.summary|safe }}</p>
                  <ul class="pager">
                    <li class="next">
                        <a href="{% url 'detail' blog.id %}">Read More &rarr;</a>
                    </li>
                </ul>
                <hr>
             {% endfor %}

                     <!-- Pager -->
                <!-- <ul class="pager">
                    <li class="next">
                        <a href="base.html">Older Posts &rarr;</a>
                    </li> -->


{% if blogs.has_other_pages %}
    <ul class="pagination">
        {% if blogs.has_previous %}
            <li><a href="?page={{ blogs.previous_page_number }}">&laquo;</a></li>
        {% else %}
            <li class="disabled"><span>&laquo;</span></li>
        {% endif %}

        {% for i in blogs.paginator.page_range %}
            {% if blogs.number == i %}
                <li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
            {% else %}
                <li><a href="?page={{ i }}">{{ i }}</a></li>
            {% endif %}
        {% endfor %}

        {% if blogs.has_next %}
            <li><a href="?page={{ blogs.next_page_number }}">&raquo;</a></li>
        {% else %}
            <li class="disabled"><span>&raquo;</span></li>
        {% endif %}
    </ul>
{% endif %}

               </ul>
            </div>
        </div>
    </div> 




<!-- Next Page
<div class="container">
<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-center">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#">Next</a>
    </li>
  </ul>
</nav>
</div> -->
    <hr>

    <!-- Footer -->
    <footer>
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    <ul class="list-inline text-center">
                        <li>
                            <a href="#">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    </ul>
                    <p class="copyright text-muted">Copyright &copy; Advice lancing 2020</p>
                </div>
            </div>
        </div>
    </footer>

    <!-- jQuery -->
    <script src="{% static 'vendor/jquery/jquery.min.js' %}"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="{% static 'vendor/bootstrap/js/bootstrap.min.js' %}"></script>

    <!-- Contact Form JavaScript -->
    <script src="{% static 'js/jqBootstrapValidation.js' %}"></script>
    <script src="{% static 'js/contact_me.js' %}"></script>

    <!-- Theme JavaScript -->
    <script src="{% static 'js/clean-blog.min.js' %}"></script>

</body>

</html>

my views.py

from django.shortcuts import render,get_object_or_404
from .models import Blog,Comment
from taggit.models import Tag
from .forms import CommentForm
from django.utils import timezone
from django.db.models import Count
from django.core.paginator import (Paginator,EmptyPage, PageNotAnInteger)


def allblogs(request, tag_slug=None):
    blogs = Blog.objects.filter(publish_date__lte=timezone.now()).order_by('-publish_date')
    object_list = Blog.objects.order_by('-publish_date')
    page = request.GET.get('page', 1)

    paginator = Paginator(object_list, 3)
    try:
        blogs = paginator.page(page)
    except PageNotAnInteger:
        blogs = paginator.page(1)
    except EmptyPage:
        blogs = paginator.page(paginator.num_pages)

    return render(request, 'blog/allblogs.html', { 'blogs':blogs})

def detail(request, blog_id):
    blogdetail = get_object_or_404(Blog, pk=blog_id)


    comments = blogdetail.comments.filter(active = True)

    new_comment = None

    if request.method == "POST":
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():
            new_comment = comment_form.save(commit = False)
            new_comment.blog = blogdetail 
            new_comment.save()
    else:
        comment_form = CommentForm()
    return render(request, 'blog/detail.html', {'blog':blogdetail, 'comments':comments, "new_comment":new_comment,'comment_form':comment_form,})

def about(request):
    return render(request, 'blog/about.html')

def contact(request):
    return render(request, 'blog/contact.html')

admin.py

from django.contrib import admin
from .models import Blog, Comment
from django.db import models
#from markdownx.admin import MarkdownxModelAdmin
from markdownx.widgets import AdminMarkdownxWidget
admin.site.site_header = 'Advice Lance'



class MyModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': AdminMarkdownxWidget},
    }

class BlogAdmin(admin.ModelAdmin):
    list_filter = ['publish_date']
admin.site.register(Blog, BlogAdmin)

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('name', 'email','active')
    list_filter = ('creadted',)

...