为什么我会收到 404?
Why do I get a 404?
我正在尝试按照本教程进行操作 https://simpleisbetterthancomplex.com/tutorial/2017/03/13/how-to-create-infinite-scroll-with-django.html 但是由于某些原因,当我尝试加载页面时我得到
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',
]
我还通过 "pip install django-jquery" 安装了 jQuery,还通过 "npm install waypoints"
安装了 Waypoints
在static/js目录中添加jquery文件。
我正在尝试按照本教程进行操作 https://simpleisbetterthancomplex.com/tutorial/2017/03/13/how-to-create-infinite-scroll-with-django.html 但是由于某些原因,当我尝试加载页面时我得到
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',
]
我还通过 "pip install django-jquery" 安装了 jQuery,还通过 "npm install waypoints"
安装了 Waypoints在static/js目录中添加jquery文件。