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

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

  • 解决方法:

    • views.py- views.py
# -*- 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




404


    

404 ERROR

文件目录

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

你可能感兴趣的:(python,web框架,django等)