Django静态资源配置不好的解决方案

版权声明:此文章版权归呆呆所有,转发请注明出处! https://blog.csdn.net/zhangyu4863/article/details/82768916

静态资源配置不好的话,当你的debug=False时,你的网页上面的所有静态资源都是不能正确加载的。debug=True的话,当用户访问出错时弹出的页面又很难看

  • 解决方法:

# -*- coding: utf-8 -*-
 
from django.http import HttpResponse
from django.shortcuts import render_to_response

def func(request):  
    try:
	    pass  # 你正常的逻辑部分
    except Exception as err:
	    return render(request, "404.html")
    • 404.html- 404.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>404</title>
</head>
<body>
    <br />
    <br />
    <h1 style="text-align: center">404  ERROR</h1>
</body>
</html>

文件目录

Project
|-- demo
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- settings.py
|   |-- settings.pyc
|   |-- urls.py
|   |-- urls.pyc
|   |-- view.py
|   |-- view.pyc
|   |-- wsgi.py
|   `-- wsgi.pyc
|-- TestModel
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- admin.py
|   |-- admin.pyc
|   |-- apps.py
|   |-- migrations
|   |   |-- __init__.py
|   |   `-- __init__.pyc
|   |-- models.py
|   |-- models.pyc
|   |-- tests.py
|   `-- views.py
|-- db.sqlite3
|-- static
|    |~~~
|-- manage.py
`-- templates
    |-- main.html
    `-- 404.html

猜你喜欢

转载自blog.csdn.net/zhangyu4863/article/details/82768916