문제

Getting weird errors :

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

I have a Django app where i am using same template for two views but for the first view it is working fine but for the second view it is giving me error .... Can someone please help .. i know this question is been already asked but nothing working so far .....If anybody want to see my code let me know as it is long i haven't pasted here....

Code :

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;
}
도움이 되었습니까?

해결책

Try after changing :

<script src="/static/js/endless_on_scroll.js" type="text/javascript"></script>
<script src="/static/js/endless-pagination.js" type="text/javascript"></script>   

and

<link rel="stylesheet" type="text/css" href="/static/css/style.css">
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top