Python 为什么我要买404?
我试图遵循本教程,但由于某些原因,当我试图加载我得到的页面Python 为什么我要买404?,python,jquery,django,http-status-code-404,feed,Python,Jquery,Django,Http Status Code 404,Feed,我试图遵循本教程,但由于某些原因,当我试图加载我得到的页面 django.template.exceptions.TemplateSyntaxError:第1行的块标记“static”无效。是否忘记注册或加载此标记? "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.wayp
django.template.exceptions.TemplateSyntaxError:第1行的块标记“static”无效。
是否忘记注册或加载此标记?
"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>
{% 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 %}
设置.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})
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文件。您应该在使用标签的每个模板文件中加载
{%load static from staticfiles%}
。您显示的模板不会给出该错误,因为您在使用静态标记之前加载了它。错误必须发生在未显示的其他模板中。另外,{%load static from staticfiles%}
已被弃用-只需使用{%load static%}
。我们无法真正帮助您使用404,因为您没有说明静态文件在项目中的位置,或者你是什么。@Alasdair我没有更改静态文件设置:static_URL='/static/,而且我也没有其他模板。请查看我链接到的文档-不仅仅是设置static_URL='/static/'
。我在哪里可以找到该文件?在根目录中创建一个目录static/js并放入里面有密码。对于jquery,您将在“static/js”中创建一个名为jquery-3.1.1.min.js的文件,并将代码放入其中。你也需要为另外两个人做这件事。