Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django开发服务器。CSS文件被用作';text/html';_Python_Html_Css_Django_Django Dev Server - Fatal编程技术网

Python Django开发服务器。CSS文件被用作';text/html';

Python Django开发服务器。CSS文件被用作';text/html';,python,html,css,django,django-dev-server,Python,Html,Css,Django,Django Dev Server,我正在使用Django 1.8。我的两个css文件的状态都是200,但firefox显示: The stylesheet http://localhost:8000/css/full-width-pics.css was not loaded because its MIME type, "text/html", is not "text/css". localhost:8000 The stylesheet http://localhost:8000/css/mainstyle.css was

我正在使用Django 1.8。我的两个css文件的状态都是200,但firefox显示:

The stylesheet http://localhost:8000/css/full-width-pics.css was not loaded because its MIME type, "text/html", is not "text/css". localhost:8000
The stylesheet http://localhost:8000/css/mainstyle.css was not loaded because its MIME type, "text/html", is not "text/css". localhost:8000
无论出于何种原因,这些文件都被用作text/html而不是text/css。这是我的html

  <link href="css/full-width-pics.css" rel="stylesheet" type="text/css" />
    <link href="css/mainstyle.css" rel="stylesheet" type="text/css" />

这在base.html文件中。我在index.html文件中扩展了base.html。在我开始使用模板继承和index.html中的所有内容之前,它工作得很好

我在Ubuntu上。我检查了/etc/mime.types。css与text/css一起列出


这让我非常困惑

2020年答案:

如果您想通过浏览器自动检测任何mime内容类型,这就是解决方案

def fetch(request):
    import mimetypes
    clientRequestUrl=os.getcwd()+'/servlet'+request.path
    try: return HttpResponse(fread(clientRequestUrl), content_type=mimetypes.guess_type(request.path)[0])
    except Exception as e: return HttpResponse(str(e)+'===> Error Thrown <br>')
经过多次痛苦的失败静态尝试后,这就是动态解决方案

def fetch(request):
    import mimetypes
    clientRequestUrl=os.getcwd()+'/servlet'+request.path
    try: return HttpResponse(fread(clientRequestUrl), content_type=mimetypes.guess_type(request.path)[0])
    except Exception as e: return HttpResponse(str(e)+'===> Error Thrown <br>')
def提取(请求):
导入模拟类型
clientRequestUrl=os.getcwd()+'/servlet'+request.path
try:返回HttpResponse(fread(clientrequestur),content\u type=mimetypes.guess\u type(request.path)[0])
异常除外,如e:返回HttpResponse(str(e)+'==>抛出错误
  • 这里fread()在try中直接读取文件,但它只是一个I/O包装器
  • 在try block-->content\u type=mimetypes.guess\u type(request.path)[0]中执行MIME检测魔法[0]ie第一个元素是必需的,因为它返回一个元组,第一个是MIME类型,第二个是编码
  • request.path在上面一行中传递,因为它根据文件路径猜测MIME。例如,如果客户端(浏览器)请求,名为stylsheet.css的文件的text/css
  • clientRequestUrl=客户端试图向服务器请求的确切url

  • 2020年答案:

    如果您想通过浏览器自动检测任何mime内容类型,这就是解决方案

    def fetch(request):
        import mimetypes
        clientRequestUrl=os.getcwd()+'/servlet'+request.path
        try: return HttpResponse(fread(clientRequestUrl), content_type=mimetypes.guess_type(request.path)[0])
        except Exception as e: return HttpResponse(str(e)+'===> Error Thrown <br>')
    
    经过多次痛苦的失败静态尝试后,这就是动态解决方案

    def fetch(request):
        import mimetypes
        clientRequestUrl=os.getcwd()+'/servlet'+request.path
        try: return HttpResponse(fread(clientRequestUrl), content_type=mimetypes.guess_type(request.path)[0])
        except Exception as e: return HttpResponse(str(e)+'===> Error Thrown <br>')
    
    def提取(请求):
    导入模拟类型
    clientRequestUrl=os.getcwd()+'/servlet'+request.path
    try:返回HttpResponse(fread(clientrequestur),content\u type=mimetypes.guess\u type(request.path)[0])
    异常除外,如e:返回HttpResponse(str(e)+'==>抛出错误
    • 这里fread()在try中直接读取文件,但它只是一个I/O包装器
    • 在try block-->content\u type=mimetypes.guess\u type(request.path)[0]中执行MIME检测魔法[0]ie第一个元素是必需的,因为它返回一个元组,第一个是MIME类型,第二个是编码
    • request.path在上面一行中传递,因为它根据文件路径猜测MIME。例如,如果客户端(浏览器)请求,名为stylsheet.css的文件的text/css
    • clientRequestUrl=客户端试图向服务器请求的确切url

    /etc/mime.types用于系统本身,应用程序不一定使用它。您可以查看Django的设置。有帮助吗?我也试过了。这对我不起作用。在stackoverflow的某个地方,我读到Django使用Python的Mime类型,这取决于系统Mime类型。您的设置是
    DEBUG=False
    ?您的url配置是什么?您是否检查过开发环境的此配置:您可以共享您的urlconf吗?/etc/mime.types用于系统本身,应用程序不一定使用它。您可以查看Django的设置。有帮助吗?我也试过了。这对我不起作用。在stackoverflow的某个地方,我读到Django使用Python的Mime类型,这取决于系统Mime类型。您的设置是
    DEBUG=False
    ?您的url配置是什么?您是否已检查开发环境的此配置:能否共享您的urlconf?