javascript - chrome 上的 contentType 错误

标签 javascript python css django django-endless-pagination

出现奇怪的错误:

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

代码:

View .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;
}

最佳答案

改完试试:

<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">

关于javascript - chrome 上的 contentType 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17722443/

相关文章:

python - 迭代字典列表时获取字典列表的索引

python - 在 python 脚本中将参数传递给 scrapy spider

Python:无法从 C 扩展继承

html - 将屏幕分成 4 个矩形,高度为 50%,宽度为 50%

Javascript - 如何快速构造不同正整数数组的二进制表示

javascript - 谷歌API : Infowindow Content Issue

javascript - 如何在 Perl 中向 ajaxError 返回数据

Javascript - 打破无限循环?

javascript - “关闭”按钮一分钟都不会关闭弹出窗口

javascript - 如何使用 glyphicon 上传图像而不是使用那个长输入字段?