问题描述
先帖代码跟项目结构项目结构
├── gameOps│ ├── __init__.py│ ├── settings.py│ ├── urls.py│ └── wsgi.py├── manage.py├── dufgame│ ├── admin.py│ ├── apps.py│ ├── __init__.py│ ├── models.py│ ├── signals.py│ ├── templates│ │ └── dufindex.html│ ├── tests.py│ ├── urls.py│ └── views.py├── run.py├── static│ ├── css│ │ ├── base.css│ │ ├── bootstrap.css│ │ ├── bootstrap.css.map│ │ ├── bootstrap.min.css│ │ ├── bootstrap-theme.css│ │ ├── bootstrap-theme.css.map│ │ └── bootstrap-theme.min.css│ ├── fonts│ │ ├── glyphicons-halflings-regular.eot│ │ ├── glyphicons-halflings-regular.svg│ │ ├── glyphicons-halflings-regular.ttf│ │ └── glyphicons-halflings-regular.woff│ └── js│ ├── bootstrap.js│ ├── bootstrap.min.js│ ├── jquery.js│ ├── jquery.min.js│ └── npm.js└── templates ├── base.html ├── leftpage.html └── tmp.html
templates/base.html 为基础模板访问:http://192.168.50.137:8000/呈现的是base.html内容dufgame/templates/dufindex.html中的内容部分继承了templates/base.html中的内容访问:http://192.168.50.137:8000/duf/呈现的是dufgame/templates/dufindex.html中的内容
gameOps/setting.py中关于静态文件的设置
STATIC_URL = '/static/'STATICFILES_DIRS = (os.path.join(BASE_DIR,'static'),)
templates/base.html中的静态文件内容
<meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Game Ops</title>{% load staticfiles %}<link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet"><link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"><link href="{% static "css/base.css" %}" rel="stylesheet">
访问:http://192.168.50.137:8000/duf/打印的日志信息
INFO "GET /duf/ HTTP/1.1" 200 8634INFO "GET /static/css/base.css HTTP/1.1" 304 0WARNING "GET /duf/static/js/jquery.min.js HTTP/1.1" 404 2789WARNING "GET /duf/static/js/bootstrap.min.js HTTP/1.1" 404 2798WARNING "GET /duf/static/js/jquery.min.js HTTP/1.1" 404 2789WARNING "GET /duf/static/js/bootstrap.min.js HTTP/1.1" 404 2798
问题来了,我的静态文件要怎么设置才能在访问http://192.168.50.137:8000/duf/时候也能调用到。
问题解答
回答1:可以参考这个来定义static文件https://segmentfault.com/a/1190000007132294