出现奇怪的错误:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8000/search/static/css/style.css". localhost/:4
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8000/search/static/js/endless_on_scroll.js". localhost/:119
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8000/search/static/js/endless-pagination.js". localhost/:119
Uncaught SyntaxError: Unexpected identifier endless_on_scroll.js:1
Uncaught SyntaxError: Unexpected identifier endless-pagination.js:1
Uncaught TypeError: Object function ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
} has no method 'endlessPaginate' ?keyWord=women:123
我有一个Django应用程序,我在两个视图使用相同的模板但是对于第一个视图它工作正常但是对于第二个视图它给了我错误....有人可以帮助..我知道这个问题已经被问到但到目前为止没有任何工作.....如果有人想看到我的代码让我知道,因为它很久没有粘贴在这里......
代码:
views.py:
import json
import traceback
from django.http import HttpResponse
from django.template import Context,loader
from django.template import RequestContext
from django.shortcuts import render_to_response
from eScraperInterfaceApp.eScraperUtils import eScraperUtils
#------------------------------------------------------------------------------
def renderError(message):
"""
This function displays error message
"""
t = loader.get_template("error.html")
c = Context({ 'Message':message})
return HttpResponse(t.render(c))
def index(request,template = 'index.html',
page_template = 'index_page.html' ):
"""
This function handles request for index page
"""
try:
context = {}
contextList = []
utilsOBJ = eScraperUtils()
q = {"size" : 300000,
"query" :{ "match_all" : { "boost" : 1.2 }}}
results = utilsOBJ.search(q)
for i in results['hits']['hits']:
contextDict = i['_source']
contextDict['image_paths'] = json.loads(contextDict['image_paths'])
contextList.append(contextDict)
context.update({'contextList':contextList,'page_template': page_template})
if request.is_ajax(): # override the template and use the 'page' style instead.
template = page_template
return render_to_response(
template, context, context_instance=RequestContext(request) )
except :
return renderError('%s' % (traceback.format_exc()))
def search (request,template = 'index.html',
page_template = 'index_page.html' ):
try:
context = {}
contextList = []
utilsOBJ = eScraperUtils()
keyWord = request.GET['keyWord']
results = utilsOBJ.search('productCategory:%(keyWord)s or productSubCategory:%(keyWord)s or productDesc:%(keyWord)s' % {'keyWord' : keyWord})
for i in results['hits']['hits']:
contextDict = i['_source']
contextDict['image_paths'] = json.loads(contextDict['image_paths'])
contextList.append(contextDict)
context.update({'contextList':contextList,'page_template': page_template})
if request.is_ajax(): # override the template and use the 'page' style instead.
template = page_template
return render_to_response(
template, context, context_instance=RequestContext(request) )
except :
return renderError('%s' % (traceback.format_exc()))
#------------------------------------------------------------------------------
index.html:
<html>
<head>
<title>Fashion</title>
<link rel="stylesheet" type="text/css" href="static/css/style.css">
</head>
<body>
<form action="/search/" method='get'>
<input id="keyWord" type="text" name="keyWord"/>
<input id="search-submit" type="submit" value="Search" />
</form>
<div class="product_container">
<ul class="product_list">
<div class="endless_page_template">
{% include page_template %}
</div>
</ul>
</div>
{% block js %}
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="static/js/endless_on_scroll.js" type="text/javascript"></script>
<script src="static/js/endless-pagination.js" type="text/javascript"></script>
<script type="text/javascript">
$.endlessPaginate({paginateOnScroll: true,
endless_on_scroll_margin : 10,
paginateOnScrollChunkSize: 5
});</script>
{% endblock %}
</body>
</html>
index_page.html:
{% load endless %}
{% paginate 10 contextList %}
{% for item in contextList %}
<li style="list-style-type: none;" >
<a href="{{ item.productURL }}" ><img src="/images/{{ item.image_paths.0 }}/" height="100" width="100" border='1px solid'/></a>
<br>
<span class="price">
<span class="mrp">MRP : {{ item.productMRP}}</span>
{% if item.productPrice %}<br>
<span class="discounted_price">Offer Price : {{ item.productPrice}}</span>
{%endif%}
</span>
</li>
{% endfor %}
{% show_more "even more" "working" %}
style.css:
.product_list
{
margin:0;
padding:0;
}
.product_list li
{
margin:0;
padding:0;
height:150px;
margin-bottom:5px;
}
.product_container
{
width:800px;
column-gap: 0;
column-count: 2;
-moz-column-gap: 0;
-moz-column-count: 2;
-webkit-column-gap: 0;
-webkit-column-count: 2;
}
答案 0 :(得分:2)
更改后尝试:
<script src="/static/js/endless_on_scroll.js" type="text/javascript"></script>
<script src="/static/js/endless-pagination.js" type="text/javascript"></script>
和
<link rel="stylesheet" type="text/css" href="/static/css/style.css">