简体   繁体   中英

Why do I get a 404?

I am trying to follow this tutorial https://simpleisbetterthancomplex.com/tutorial/2017/03/13/how-to-create-infinite-scroll-with-django.html but for some reason when I try to load the page I get

django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 1: 'static'. Did you forget to register or load this tag?

 "GET / HTTP/1.1" 500 141448``
 "GET / HTTP/1.1" 200 167
 "GET /static/js/jquery-3.1.1.min.js HTTP/1.1" 404 1690
 "GET /static/js/jquery.waypoints.min.js HTTP/1.1" 404 1702
 "GET /static/js/infinite.min.js HTTP/1.1" 404 1678
 "GET /static/js/jquery.waypoints.min.js HTTP/1.1" 404 1702
 "GET /static/js/infinite.min.js HTTP/1.1" 404 1678

base.html

{% load static from staticfiles %}

<script src="{% static 'js/jquery-3.1.1.min.js' %}"></script>
<script src="{% static 'js/jquery.waypoints.min.js' %}"></script>
<script src="{% static 'js/infinite.min.js' %}"></script>

home.html

{% extends 'base.html' %}

{% block content %}
  <div class="infinite-container">
    {% for number in numbers %}
      <div class="infinite-item">{{ number }}</div>
    {% endfor %}
  </div>

  {% if numbers.has_next %}
    <a class="infinite-more-link" href="?page={{ numbers.next_page_number }}">More</a>
  {% endif %}

  <script>
    var infinite = new Waypoint.Infinite({
      element: $('.infinite-container')[0]
    });
  </script>
{% endblock %}

views.py

from django.shortcuts import render

from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger


def home(request):
    numbers_list = range(1, 1000)
    page = request.GET.get('page', 1)
    paginator = Paginator(numbers_list, 20)
    try:
        numbers = paginator.page(page)
    except PageNotAnInteger:
        numbers = paginator.page(1)
    except EmptyPage:
        numbers = paginator.page(paginator.num_pages)
    return render(request, 'home.html', {'numbers': numbers})

settings.py

INSTALLED_APPS = [
    'jquery',
    'feedApp',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

I also installed jQuery by "pip install django-jquery" and also Waypoints by "npm install waypoints"

将jquery文件添加到static / js目录中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM