0

出现奇怪的错误:

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 应用程序,我在其中对两个视图使用相同的模板,但是对于第一个视图,它工作正常,但是对于第二个视图,它给了我错误.. 有人可以帮忙.. 我知道这个问题已经问但到目前为止没有任何工作.....如果有人想查看我的代码,请告诉我,因为它很长我还没有粘贴在这里....

代码 :

视图.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()))

#------------------------------------------------------------------------------     

索引.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" %}

样式.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;
}
4

1 回答 1

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">
于 2013-07-18T13:04:10.610 回答