A
A
aab1372018-09-10 05:53:40
Django
aab137, 2018-09-10 05:53:40

Not all posts are displayed. What to do?

I wrote 5 posts in the admin panel, 1 is displayed on the site
. really hard to figure it out.
Here is what is in the project (except venv):

├── db.sqlite3
├── mainApp
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── admin.cpython-36.pyc
│   │   ├── models.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   └── views.cpython-36.pyc
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   ├── __init__.py
│   │   └── __pycache__
│   │       └── __init__.cpython-36.pyc
│   ├── models.py
│   ├── templates
│   │   └── mainApp
│   │       ├── homePage.html
│   │       └── wrapper.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── settings.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   └── wsgi.cpython-36.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── myvenv
│   └── …
└── news
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-36.pyc
    │   ├── admin.cpython-36.pyc
    │   ├── models.cpython-36.pyc
    │   └── urls.cpython-36.pyc
    ├── admin.py
    ├── apps.py
    ├── migrations
    │   ├── 0001_initial.py
    │   ├── __init__.py
    │   └── __pycache__
    │       ├── 0001_initial.cpython-36.pyc
    │       └── __init__.cpython-36.pyc
    ├── models.py
    ├── templates
    │   └── news
    │       └── posts.html
    ├── tests.py
    ├── urls.py
    └── views.py

What is displayed on the site: alexbiryuckoff.pythonanywhere.com/news
mysite/urls.py:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('mainApp.urls')),
    url(r'^news/', include('news.urls')),
]

news/urls.py:
from django.conf.urls import url
from django.views.generic import ListView, DetailView
from news.models import Articles

urlpatterns = [
    url(
        r'^$',
        ListView.as_view(queryset = Articles.objects.filter(id = 2).order_by("-date")[:20],
        template_name="news/posts.html")
    )
]

news/templates/news/posts.html:
{% extends "mainApp/wrapper.html" %}

{% block content %}
    {% for post in object_list %}
        <a href="/news/{{post.id}}"><h3>{{post.title}}</h3></a>
        <h5>{{post.date|date:"d-m-Y"}}</h5>
        <p>{{post.post}}</p>
    {% endfor %}
{% endblock %}

news/models.py:
from django.db import models
class Articles(models.Model):
    title = models.CharField(max_length=120)
    post = models.TextField()
    date = models.DateTimeField()
    def __str__(self):
        return self.title

news/admin.py:
from django.contrib import admin
from news.models import Articles
admin.site.register(Articles)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question